Calling Procedures

Dave_B_C
Dave_B_C used Ask the Experts™
on
I am trying to call a procedure in another .pas file.
However it does not compile with a message that 'this form of method call only allowed for class methods'. What am I doing wrong? Relevant code from the 2 modules below...

Cheers,

Dave

Unit GRUnit2;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,
  StdCtrls, ComCtrls, ExtCtrls, DB, ADODB, Grids, DBGrids, DBCtrls, Mask, GRUnit3;

type


  TForm2 = class(TForm)
    StatusBar: TStatusBar;
    procedure Main_Process_Loop(Sender: TObject);
  end;

var


  Button: integer;


implementation

{$R *.dfm}
procedure TForm2.Main_Process_Loop(Sender: TObject);

begin
     
      button:=MessageDlg('Write File?',mtConfirmation,[MbYes,MbNo],0);
      if button = mrYes then begin
           TForm3.Write_File; {Writes output}
           showmessage('File written');
           end;
      end;
end.

unit GRUnit3;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls, Mask, DBCtrls, DB, Grids, DBGrids, ADODB, ExtCtrls;

type
  TForm3 = class(TForm)
    Procedure Write_File;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form3: TForm3;

implementation

{$R *.dfm}

Procedure TForm3.Write_File;
begin;
      showmessage('Start');
end;

end.
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
you might try to change the


TForm3.Write_File;


to


Form3.Write_File;
Commented:
Hi,

TForm3 = class(TForm)
   Procedure Write_File;
 private
   { Private declarations }
 public
   { Public declarations }
 end;

  First of all move "procedure Write_file;"
Move it under Public. At GRUnit2 add uses GRUnit3; under implementation and do not call it using Tform3.Write_File; TForm3 is a class itself. You have to use Form3.Write_File.

Hope that works.

Author

Commented:
Nice one Dumani, thanks.!Also thanks to Slick who was on the right track!

Dave

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial