Discussion:
Why does it NOT FAILl?
(too old to reply)
Ephraim
2008-05-27 15:22:56 UTC
Permalink
RAD 2007 Teial

I have not created an instance of DataModule2nor auto-create, yet no AV when
I press the button TForm1.Button1Click(Sender: TObject);
Is this code treated as a class procedure? Why does it not fail?

TIA

Ephraim


Project Source

program Project1;

uses
Forms,
Unit1 in 'Unit1.pas' {Form1},
Unit2 in 'Unit2.pas' {DataModule2: TDataModule};

{$R *.res}

begin
Application.Initialize;
Application.MainFormOnTaskbar := True;
Application.CreateForm(TForm1, Form1);
Application.Run;
end.

I create this form

unit Unit1;

interface

uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls{, Project2_TLB};

type
TForm1 = class(TForm)
Button1: TButton;
Button2: TButton;
procedure Button1Click(Sender: TObject);
procedure Button2Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;

implementation

uses Unit2;


{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
begin
DataModule2.ShowMe('Poor Chelsea');
end;

procedure TForm1.Button2Click(Sender: TObject);
//var
// IDispl: IDisplay;
begin
// IDispl:=CoDisplay.Create;
// IDispl.DisplayMessage('This works')
end;

end.
and this DataModule

unit Unit2;

interface

uses
SysUtils, Classes, Dialogs;

type
TDataModule2 = class(TDataModule)
private
{ Private declarations }
public
{ Public declarations }
procedure ShowMe(const Text: String);
end;

var
DataModule2: TDataModule2;

implementation

{$R *.dfm}

{ TDataModule2 }

procedure TDataModule2.ShowMe(const Text: String);
begin
ShowMessage(Text)
end;

end.
Marc Rohloff [TeamB]
2008-05-27 17:59:13 UTC
Permalink
Post by Ephraim
I have not created an instance of DataModule2nor auto-create, yet no AV when
I press the button TForm1.Button1Click(Sender: TObject);
Is this code treated as a class procedure? Why does it not fail?
Because the method never attempts to access any of the fields of the
datamodule or any virtual methods. If it did then you would get the
error at that point.

BTW, This group is for questions about upgrades. I suggest that you
choose an appropriate group next time, you will get better answers
that way.
--
Marc Rohloff [TeamB]
marc -at- marc rohloff -dot- com
Loading...