Recent

Author Topic: RegisterClass  (Read 8805 times)

Dibo

  • Hero Member
  • *****
  • Posts: 1048
RegisterClass
« on: September 07, 2008, 08:07:31 pm »
Hi, Sorry for my English ;)

I'm trying write uniwersal procedure to show any form class. So, in Turbo Delphi it work ok, but in lazarus I couldn't find RegisterClass with TPressistentClass parameter. I found only with TWndClass. So do something like this:
Code: [Select]

procedure TBaseFormManager.BaseRegisterClass(iClass: TPersistentClass);
 var
  aWndClass: TWNDCLASSEX;
  p: PChar;
begin
  aWndClass.cbSize := SizeOf(TWNDCLASSEX);
  aWndClass.style := CS_GLOBALCLASS;
  aWndClass.lpfnWndProc:= nil;
  aWndClass.cbClsExtra := 0;
  aWndClass.cbWndExtra := 0;
  aWndClass.hInstance := HINSTANCE;
  aWndClass.hIcon:=0;
  aWndClass.hCursor:=0;
  aWndClass.hbrBackground:=COLOR_BTNSHADOW;
  aWndClass.lpszMenuName:=nil;
  aWndClass.lpszClassName := PChar(String(iClass.ClassName));
  aWndClass.hIconSm := 0;
  RegisterClassEx(aWndClass);
  Logger('Last Error: '+IntToStr(GetLastError));
  FRegisteredClassList.Add(iClass.ClassName);
end;

Then when I want create form I call this procedure:

Code: [Select]
procedure TBaseFormManager.CreateTabForm(iOwner: TComponent; iClassName: String);
 var
  aForm: TFormClass;
begin
  aForm := TFormClass(FindClass(iClassName));
  with aForm.Create(iOwner) do begin
    Show;
  end;
end;  

I have error "class not found". After RegisterClass I call GetLastError but it receive 0 (no errors). How can I do this like in Delphi?

P.S. Is RegisterClass compatible with linux system? Now I'm writing for windows but maybe in future for linux. I never write for linux using lazarus.

Leledumbo

  • Hero Member
  • *****
  • Posts: 8757
  • Programming + Glam Metal + Tae Kwon Do = Me
RE: RegisterClass
« Reply #1 on: September 08, 2008, 06:05:32 am »
Wow... it looks like very WinAPI, eh? If you want to make sure that it's platform independent, try removing Windows, Messages, and all WinAPI specific units with Lazarus cross-platform ones (LCLIntf, LCLType, LCLProc, LMessages, etc.).

Dibo

  • Hero Member
  • *****
  • Posts: 1048
RE: RegisterClass
« Reply #2 on: September 08, 2008, 07:10:15 pm »
Thanks Leledumbo! Now I see RegisterClass with TPersistentclass parameter and creating form work great :D

 

TinyPortal © 2005-2018