Recent

Author Topic: Inserting a Runtime Control (solved)  (Read 3113 times)

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Inserting a Runtime Control (solved)
« on: April 06, 2013, 03:23:05 am »
Code: [Select]
var
fButton: TButton;
selfh:HWND;
begin
fButton := TButton.Create(Selfh); //self to selfh for threadsafe
fButton.Caption := 'pause';
fbutton.OnClick := fButton1Click;
Self.InsertControl( fButton ); //ERROR HERE > unknown identifier InsertControl
end;

But if I'll not use a class(TThread) theres no problem in the code.
Whats the alternative for threadsafe InsertControl?
« Last Edit: April 06, 2013, 11:44:24 am by xenblaise »

taazz

  • Hero Member
  • *****
  • Posts: 5368
Re: Inserting a Runtime Control
« Reply #1 on: April 06, 2013, 04:07:35 am »
Self is an alias for the pointer of an object that can only be used inside an object's methods.
You are not giving us enough information to even know what you are trying to do.
In sort you can not create and use components outside the main thread, InsertControl is a TWinControl method that means that the control you are building must inherit from twincontrol or control based on twincontrol. If you are writing a TThread descendant then it definitely does not support that method.
Good judgement is the result of experience … Experience is the result of bad judgement.

OS : Windows 7 64 bit
Laz: Lazarus 1.4.4 FPC 2.6.4 i386-win32-win32/win64

User137

  • Hero Member
  • *****
  • Posts: 1791
    • Nxpascal home
Re: Inserting a Runtime Control
« Reply #2 on: April 06, 2013, 05:47:26 am »
Code: [Select]
var fButton: TButton;
    selfh:HWND;
begin
  fButton := TButton.Create(Selfh); //self to selfh for threadsafe...
TButton.Create() only takes TComponent object as parameter. There is no overloaded constructor that would accept a HWND, which in your case is even uninitialized. By your code's logic, these would be equally valid...
Code: [Select]
fButton := TButton.Create(129874124);
fButton := TButton.Create(546234234);
(Of course they're not, just showing. What happens, is that you use random number as button owner.)
« Last Edit: April 06, 2013, 05:50:26 am by User137 »

xenblaise

  • Sr. Member
  • ****
  • Posts: 358
Re: Inserting a Runtime Control
« Reply #3 on: April 06, 2013, 11:44:04 am »
Quote
taazz
If you are writing a TThread descendant then it definitely does not support that method.


Quote
User137
There is no overloaded constructor that would accept a HWND, which in your case is even uninitialized.

Yes your both right. I have a different solution now.
thanks :D

 

TinyPortal © 2005-2018