Recent

Author Topic: Regarding the issue of encapsulating TLazVirtualDrawTree as a DLL library  (Read 1710 times)

energy

  • New Member
  • *
  • Posts: 14
  • Go Energy
    • golang energy gui
Hello, I am using Golang to package Lazarus's LCL component library into a dynamic link library for Go to use.
I encountered an issue while packaging the API for the TLazVirtualDrawTree component.
Creating object TLazVirtualDrawTree.Create
In the CreateCheckImageList function, when calling CreateBitmapFromResourceName (0, resname) to create a bitmap object, find the LAZ_VT_CHECK_DARK resource. The invalid address exception is thrown because the passed in resource is 0
There is no problem with directly creating and executing the exe program in Lazarus. Only available in the DLL library.
Solution: CreateBitmapFromResourceName(HINSTANCE, resname); Only by passing in resource instances here can we create them correctly
Is there any other way besides that? Because I don't want to modify the Lazarus source code.
Maintain Golang development project: Go CEF  Go WV(Webview2, Webkit2)  Go LCL

jamie

  • Hero Member
  • *****
  • Posts: 6943
I think you should report that because I see two things wrong here.

Looking for a DARK resource and assuming 0 is ok.

There is also the VirtualTree package that is not part of the Lazarus directly but it the same, it make not be modified in such way.

You can install that on top of the Laz version.


The only true wisdom is knowing you know nothing

energy

  • New Member
  • *
  • Posts: 14
  • Go Energy
    • golang energy gui
This issue is with the LAZ library project. After compiling the DLL, when the host program loads the DLL.
When creating BitmapFromResourceName to search for resources, 0 is passed in, and the exe host program that loads the DLL is used to search for resources.
If the passed in 0 is replaced with the current DLL module handle HINSTANCE, this problem can be solved. That is to search for this resource in the DLL
I found it impossible to set this HINSTANCE externally, nor can I rewrite functions related to it.

 `You can install that on top of the Laz version.` What does it mean?

Code: Pascal  [Select][+][-]
  1. function CreateCheckImageList(CheckKind: TCheckImageKind): TImageList;
  2. {$IF LCL_FullVersion >= 2000000}
  3. var
  4.   bm: TCustomBitmap;
  5.   resName: String;
  6. {$ENDIF}
  7. begin
  8.   Result := TImageList.Create(nil);
  9.   Result.Height := 16;
  10.   Result.Width := 16;
  11.   {$IF LCL_FullVersion >= 2000000}
  12.   Result.RegisterResolutions([16, 24, 32]);
  13.   Result.Scaled := true;
  14.   resname := BuildResourceName(CheckImagesStrings[CheckKind]);
  15.   bm := CreateBitmapFromResourceName(HINSTANCE, resname);
  16.   try
  17.     bm.Transparent := true;
  18.     Result.AddSliced(bm, 25, 1);
  19.   finally
  20.     bm.Free;
  21.   end;
  22.   {$ELSE}
  23.   Result.AddResourceName(0, CheckImagesStrings[CheckKind], clFuchsia);
  24.   {$IFEND}
  25. end;
  26.  

Maintain Golang development project: Go CEF  Go WV(Webview2, Webkit2)  Go LCL

KodeZwerg

  • Hero Member
  • *****
  • Posts: 2269
  • Fifty shades of code.
    • Delphi & FreePascal
Try
Code: Pascal  [Select][+][-]
  1. HInstance := GetModuleHandle(nil);
« Last Edit: Tomorrow at 31:76:97 xm by KodeZwerg »

jamie

  • Hero Member
  • *****
  • Posts: 6943
if you go to the online package manager and download and install the VirtualTree package, which is the same as the Laz one and then you can modify that same partial of code and rebuild the IDE, it will not disrupt the LAZ version but you will be able to use that one instead.

The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12850
Just committed a version to Laz/main (and requested backporting to Laz/fixes) in which the "0" with respect to resources has been replaced by HINSTANCE at all places.

jamie

  • Hero Member
  • *****
  • Posts: 6943
Does this also cover the non-Laz version of the package ?

The only true wisdom is knowing you know nothing

wp

  • Hero Member
  • *****
  • Posts: 12850
Does this also cover the non-Laz version of the package ?
No, only laz.virtualtrees. Somebody should post a bugreport on the non-laz version's repository.

jamie

  • Hero Member
  • *****
  • Posts: 6943
Ok, looks like I need an account there, I thought I had one, but guess not.

I'll get one later and report it.
Thanks.

The only true wisdom is knowing you know nothing

energy

  • New Member
  • *
  • Posts: 14
  • Go Energy
    • golang energy gui
Thank you.
Maintain Golang development project: Go CEF  Go WV(Webview2, Webkit2)  Go LCL

 

TinyPortal © 2005-2018