Forum > General

The EnumChildWindows compilation error

<< < (2/2)

440bx:
Here are the links to the examples that involve windows and child windows:


https://forum.lazarus.freepascal.org/index.php/topic,53690.msg397423.html#msg397423
https://forum.lazarus.freepascal.org/index.php/topic,53567.msg396385.html#msg396385

Note that those examples are pure Windows API, no "Forms" and stuff like that but, they should be useful for anyone who wants to learn how Windows works.  Use the debugger "Luke". ;)

ETA:

Thank you for the "plug" KodeZwerg.

yazigegeda:

--- Quote from: 440bx on May 14, 2024, 10:19:53 am ---Here are the links to the examples that involve windows and child windows:


https://forum.lazarus.freepascal.org/index.php/topic,53690.msg397423.html#msg397423
https://forum.lazarus.freepascal.org/index.php/topic,53567.msg396385.html#msg396385

Note that those examples are pure Windows API, no "Forms" and stuff like that but, they should be useful for anyone who wants to learn how Windows works.  Use the debugger "Luke". ;)

ETA:

Thank you for the "plug" KodeZwerg.

--- End quote ---


I want to put the implementation of the button click event of Form1 in other units, I don't know if it is feasible, help me

440bx:

--- Quote from: yazigegeda on May 14, 2024, 01:18:11 pm ---I want to put the implementation of the button click event of Form1 in other units, I don't know if it is feasible, help me

--- End quote ---
I know the Windows API reasonably well and can help you with that.  I know next to nothing about writing a program the Lazarus/Delphi way, therefore it is unlikely I can be of any real help in your case, it's likely that whatever I suggest will likely be "less" than optimal (if it works at all.)

KodeZwerg:

--- Quote from: 440bx on May 14, 2024, 10:19:53 am ---Thank you for the "plug" KodeZwerg.
--- End quote ---
You are welcomed and apologies that I forgot the "b" in your nick  O:-)

--- Quote from: yazigegeda on May 14, 2024, 01:18:11 pm ---I want to put the implementation of the button click event of Form1 in other units, I don't know if it is feasible, help me
--- End quote ---
You should explain more what you actually want to achieve.
In what unit the execution code is does not matter much.

short example
unit2 got the method for a click event
unit1 got some control where the click event has matching header as the one in unit2, in code = "mycontrol.onclick := unit2.clickmethod...."
be aware about that "clickmethod" knows nothing of unit1 scope.

Remy Lebeau:

--- Quote from: yazigegeda on May 14, 2024, 09:44:32 am ---unit1.pas(44,49) Error: Incompatible type for arg no. 2: Got "<procedure variable type of function(QWord;Int64):LongBool of object;StdCall>", expected "<procedure variable type of function(QWord;Int64):LongBool;StdCall>"

--- End quote ---

You can't use a non-static class method for an Win32 API callback, because it has a hidden Self parameter that the API doesn't know what to do with.

For what you are attempting, you can use a class static method instead, eg:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  TForm1 = class(TForm)    ...    procedure FormCreate(Sender: TObject);    class function WindowsToList(_para1: HWND; _para2: LPARAM): WINBOOL; stdcall; static;  end; ... procedure TForm1.FormCreate(Sender: TObject);begin  EnumChildWindows(Self.Handle, @WindowsToList, LPARAM(Self));end; class function TForm1.WindowsToList(_para1: HWND; _para2: LPARAM): WINBOOL; stdcall;begin  // use _para1 and TForm1(_para2) as needed...  Result := ...;end; 

--- Quote from: yazigegeda on May 14, 2024, 01:18:11 pm ---I want to put the implementation of the button click event of Form1 in other units, I don't know if it is feasible, help me

--- End quote ---

If you define the event handler as a method of the Form class (ie, by creating it at design-time), then its implementation must be in the same unit as the Form class.  Pascal simply has no concept of "partial classes" that span multiple source files, like some languages do, such as C#.

If you want the implementation to be in a different unit, then you will have to either:

- make the handler normally and simply have it call functions/methods of other units, eg:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit MyOtherUnit; interface procedure DoSomething; implementation procedure DoSomething;begin  //...end; end. 

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; interface uses  ...; type  TForm1 = class(TForm)    Button1: TButton;    procedure Button1Click(Sender: TObject);    ...  end; ... implementation ... uses  MyOtherUnit; procedure TForm1.Button1Click(Sender: TObject);begin  DoSomething;end; end. 
- create a separate object instance elsewhere as needed and then assign one of its methods as the event handler in code at runtime, eg:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit MyOtherUnit; interface type  TMyOtherClass = class  public    procedure DoSomething(Sender: TObject);  end; implementation procedure TMyOtherClass.DoSomething(Sender: TObject);begin  //...end; end. 

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---unit Unit1; interface uses  ..., MyOtherUnit; type  TForm1 = class(TForm)    Button1: TButton;    procedure FormCreate(Sender: TObject);    procedure FormDestroy(Sender: TObject);    ...  private    MyObj: TMyOtherClass;  end; ... implementation ... procedure TForm1.FormCreate(Sender: TObject);begin  MyObj := TMyOtherClass.Create;  Button1.OnClick := MyObj.DoSomething;end; procedure TForm1.FormDestroy(Sender: TObject);begin  MyObj.Free;end; end. 

Navigation

[0] Message Index

[*] Previous page

Go to full version