Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Why does this NOT FAIL?

0 views
Skip to first unread message

Ephraim

unread,
May 27, 2008, 11:16:59 AM5/27/08
to
RAD 2007 Teial

I have not created an instance of DataModule2nor aut-=creation, 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.


Ephraim

unread,
May 27, 2008, 11:19:34 AM5/27/08
to
RAD 2007 Teial

I have not created an instance of DataModule2 not auto-creat, yet no AV when
Ii press the button TForm1.Button1Click(Sender: TObject);

Peter Below (TeamB)

unread,
May 27, 2008, 2:31:39 PM5/27/08
to
Ephraim wrote:

> RAD 2007 Teial
>
> I have not created an instance of DataModule2nor aut-=creation, 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?
>

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

It does not fail because this method does not make any use of the Self
parameter, the datamodules address. This it is not accessed its value
is not important. As soon as you tried to access a field of the
datamodule or call a virtual method it would blow up with an access
violation.

--
Peter Below (TeamB)
Don't be a vampire (http://slash7.com/pages/vampires),
use the newsgroup archives :
http://www.tamaracka.com/search.htm
http://groups.google.com

Remy Lebeau (TeamB)

unread,
May 27, 2008, 5:55:59 PM5/27/08
to

"Ephraim" <Kos...@nospam.com> wrote in message
news:483c...@newsgroups.borland.com...

> Why does it not fail?

Because you are not actually accessing any of the DataModule's members
inside of ShowMe(). When you call a class method via an invalid object
pointer, no error occurs until the Self pointer inside the method is
actually used.


Gambit


0 new messages