[Lazarus] Call a KOL Form public method from a simple unit
User
usuarioanonimomysql at gmail.com
Tue Dec 30 21:23:28 CET 2008
The solution is to use {$mode delphi} or to use the classic syntax to
call object's methods:
Form2^.PublicMethod;
2008/12/30 User <usuarioanonimomysql at gmail.com>:
> Hi, I want to call a KOL Form public method (procedure PublicMethod;
> of Unit3) from a simple unit (Unit2) but the public method is not
> recognized. Why?
>
> My code:
>
> project1.lpr:
>
> { KOL MCK } // Do not remove this line!
> {$DEFINE KOL_MCK}
> {$ifdef FPC} {$mode delphi} {$endif}
> program project1;
>
> uses
> KOL,
> Unit1, Unit2, Unit3;
>
> begin // PROGRAM START HERE -- Please do not remove this comment
>
> {$IFNDEF LAZIDE_MCK} {$I project1_0.inc} {$ELSE}
>
> Application.Initialize;
> Application.Run;
>
> {$ENDIF}
>
> end.
>
> Unit1:
>
> { KOL MCK } // Do not remove this line!
> {$DEFINE KOL_MCK}
> {$ifdef FPC} {$mode delphi} {$endif}
> unit Unit1;
>
> interface
>
> uses Windows, Messages, KOL {place your units here->}
> {$IFDEF LAZIDE_MCK}, Forms, mirror, Classes, Controls, mckCtrls,
> mckObjs, Graphics;
> {$ELSE} ; {$ENDIF}
>
> type
> { TForm1 }
> {$I MCKfakeClasses.inc}
> {$IFDEF KOLCLASSES} TForm1 = class; PForm1 = TForm1; {$ELSE OBJECTS}
> PForm1 = ^TForm1; {$ENDIF CLASSES/OBJECTS}
> TForm1 = {$IFDEF KOLCLASSES}class{$ELSE}object{$ENDIF}({$IFDEF
> LAZIDE_MCK}TForm{$ELSE}TObj{$ENDIF})
> Form: PControl;
> KOLForm1: TKOLForm;
> KOLProject: TKOLProject;
> private
> { private declarations }
> public
> { public declarations }
> end;
>
> var
> Form1 {$IFDEF KOL_MCK} : PForm1 {$ELSE} : TForm1 {$ENDIF} ;
>
> {$IFDEF KOL_MCK}
> procedure NewForm1( var Result: PForm1; AParent: PControl );
> {$ENDIF}
>
> implementation
>
> {$IFDEF KOL_MCK}
> {$I unit1_1.inc}
> {$ENDIF}
>
> initialization
> {$IFNDEF KOL_MCK} {$I unit1.lrs} {$ENDIF}
>
> end.
>
> Unit2:
>
> unit Unit2;
>
> {$mode objfpc}{$H+}
>
> interface
>
> uses
> Classes, SysUtils;
>
> type
> cClass = class
> private
> procedure Call;
> public
> end;
>
> implementation
>
> uses Unit3;
>
> procedure cClass.Call;
> begin
> Form2.
> end;
>
> end.
>
> Unit3:
>
> { KOL MCK } // Do not remove this line!
> {$DEFINE KOL_MCK}
> {$ifdef FPC} {$mode delphi} {$endif}
> unit Unit3;
>
> interface
>
> uses Windows, Messages, KOL {place your units here->}
> {$IFDEF LAZIDE_MCK}, Forms, mirror, Classes, Controls, mckCtrls,
> mckObjs, Graphics;
> {$ELSE} ; {$ENDIF}
>
> type
> { TForm2 }
> {$I MCKfakeClasses.inc}
> {$IFDEF KOLCLASSES} TForm2 = class; PForm2 = TForm2; {$ELSE OBJECTS}
> PForm2 = ^TForm2; {$ENDIF CLASSES/OBJECTS}
> TForm2 = {$IFDEF KOLCLASSES}class{$ELSE}object{$ENDIF}({$IFDEF
> LAZIDE_MCK}TForm{$ELSE}TObj{$ENDIF})
> Form: PControl;
> KOLForm2: TKOLForm;
> private
> { private declarations }
> public
> { public declarations }
> procedure PublicMethod;
> end;
>
> var
> Form2 {$IFDEF KOL_MCK} : PForm2 {$ELSE} : TForm2 {$ENDIF} ;
>
> {$IFDEF KOL_MCK}
> procedure NewForm2( var Result: PForm2; AParent: PControl );
> {$ENDIF}
>
> implementation
>
> {$IFDEF KOL_MCK}
> {$I unit3_1.inc}
> {$ENDIF}
>
> procedure TForm2.PublicMethod;
> begin
>
> end;
>
> initialization
> {$IFNDEF KOL_MCK} {$I unit3.lrs} {$ENDIF}
>
> end.
>
> Best regards.
>
More information about the Lazarus
mailing list