Hi,
I am trying to assign a TBitmap to another TBitmap.
When I try to do this, I always get a EConvertError "Cannot assign a TBitmap to a TBitmap".
What !!!!???? I really don't understand this error ?
PS : The original Bitmap is loaded on a TFrame in a DLL. This DLL
is linked to a project witch contains The Bitmap to be assigned.
Here's the code :
// *********************** DLL
[code]
...
function PL_DLLGetBitmap(const pcBitmapID: string): TBitmap;
var
loDLLImage: TDLLPlaisirImage;
begin
Result := nil;
if Assigned(zoDLLPlaisirImages)
then begin
loDLLImage := zoDLLPlaisirImages.AddImage(pcBitmapID);
if Assigned(loDLLImage) then Result := loDLLImage.Image.Bitmap;
end;
end;
procedure PL_DLLSetBitmap(const pcBitmapID: string; poBitmap: TBitmap);
var
loBitmap: TBitmap;
begin
if Assigned(poBitmap)
then begin
loBitmap := PL_DLLGetBitmap(pcBitmapID);
if Assigned(loBitmap) then [red]loBitmap.Assign(poBitmap)[/red];
end;
end;
...
[/code]
// *********************** PROJECT
[code]
...
procedure TForm1.Button1Click(Sender: TObject);
begin
PL_DLLSetBitmap(Self.ComboBox1.Text, Self.Image1.Picture.Bitmap);
end;
...
[/code]
Please Help.
Comments
[code]
if Assigned(loBitmap) then loBitmap.Graphic.Assign(poBitmap.Graphic);
[/code]
hth, pritaeas
: I am trying to assign a TBitmap to another TBitmap.
: When I try to do this, I always get a EConvertError "Cannot assign a
: TBitmap to a TBitmap".
I am using Delphi 6 and a TBitmap object does implement the Assign method :
(Also, TBitmap does not have a Graphic property)
here's the code from Graphics.pas
Thanks for your help.
[code]
...
procedure TBitmap.Assign(Source: TPersistent);
var
DIB: TDIBSection;
begin
if (Source = nil) or (Source is TBitmap) then
begin
EnterCriticalSection(BitmapImageLock);
try
if Source <> nil then
begin
TBitmap(Source).FImage.Reference;
FImage.Release;
FImage := TBitmap(Source).FImage;
FTransparent := TBitmap(Source).FTransparent;
FTransparentColor := TBitmap(Source).FTransparentColor;
FTransparentMode := TBitmap(Source).FTransparentMode;
end
else
begin
FillChar(DIB, Sizeof(DIB), 0);
NewImage(0, 0, DIB, False);
end;
finally
LeaveCriticalSection(BitmapImageLock);
end;
PaletteModified := Palette <> 0;
Changed(Self);
end
else inherited Assign(Source);
end;
...
[/code]
: Hi. Assign is not implemented for a TBitmap. IIRC it _is_ implemented for TGraphic, so try
:
: [code]
: if Assigned(loBitmap) then loBitmap.Graphic.Assign(poBitmap.Graphic);
: [/code]
:
: hth, pritaeas
:
: : I am trying to assign a TBitmap to another TBitmap.
: : When I try to do this, I always get a EConvertError "Cannot assign a
: : TBitmap to a TBitmap".
:
Possibly the bitmap-class you use is not derived from TBitmap.
hth, pritaeas
[code]
var
b1, b2: TBitmap;
begin
inherited;
b1 := TBitmap.Create;
b2 := TBitmap.Create;
b1.LoadFromFile('whatever.bmp');
b2.Assign(b1);
Image1.Picture.Bitmap.Assign(b2); { placed on the form }
b1.Free;
b2.Free;
end;
[/code]
: When I try to do this, I always get a EConvertError "Cannot assign a
: TBitmap to a TBitmap".
http://newsgroups.archived.at/borland/public.delphi.graphics/200703/0703264245.html
Below is the solution from Peter B, in case the link gets broken:
> Hi there,
>
> I have a graphics library that I am packaging as a DLL.
>
> It is giving the weird exception above.
That is the typical symptom of passing an object reference to another
module when *not* building both modules with run-time packages. In this
case each module has its own independent copy of the classes involved.
They may have the same name, but the class name is not used to check
for class identity, e.g. in Assign. You can have different classes with
the same name even inside a single module, as long as they are in
different units. The IS operator uses the class records address to
identify a class, and by this criterion TBitmap in your host EXE and
TBitmap in your DLL are different classes, since they have different
addresses.
To get around that you have to build both modules with run-time
packages. You can also turn the DLL into a package while you're at it.
--