Re: Idea
From: Dragon Lord (invalid_at_joke.com)
Date: 02/03/04
- Next message: Rob Kennedy: "Re: Idea"
- Previous message: Dragon Lord: "Re: Idea"
- In reply to: Rob Kennedy: "Re: Idea"
- Next in thread: Dragon Lord: "Re: Idea"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Mon, 2 Feb 2004 22:21:19 -0500
"Rob Kennedy" <me@privacy.net> wrote in message
news:bvmrgq$u2o3o$1@ID-220940.news.uni-berlin.de...
> Dragon Lord wrote:
> > In Theory, it should compile, Since the included function are apart
> > of the object, and i'm calling them within the context of that
> > object.
>
> No, the const block declares things that reside in the data segment, not
> on the stack, so when you say that the Proc1 field is equal to
> Procedure1, there is no object reference -- no Self. The consts will be
> initialized exactly once -- when the program is compiled -- not each
> time the method gets called, and the compiler won't be able to fully
> initialize those method pointers.
>
> > If I move {$INCLUDE MyInt.INC} outside of the class and the {$INCLUDE
> > MyConst.INC} into the interface, it compiles great.
>
> Yep. But stand-alone function pointers don't carry as much information
> as method pointers do. Function pointers only point to code. Method
> pointers point to code and an object.
>
> > But I want those functions to have permissions to local private
> > varibles in the object, as it is now, I have to make all variables
> > PUBLIC and pass in the "Self" reference to each object.
>
> Not if they're all in the same unit. The public/private designations
> don't apply to code that resides in the same unit.
>
> --
> Rob
Here is a simple DISPROOF
{ Unit1.pas }
unit Unit1;
interface
type
TMyClass = class
private
X: Integer;
public
procedure PrintIt(Value: Integer);
end;
implementation
procedure TMyClass.PrintIt(Value: Integer);
begin
writeln(Value, ' = ', X);
end;
end.
{ Project1.dpr }
program Project1;
{$APPTYPE CONSOLE}
uses
SysUtils,
Unit1 in 'Unit1.pas';
type
MyProc = procedure(MySelf: Pointer; Value: Integer);
MyTRec = record
Filler: Integer;
X: Integer;
end;
Const
X: Pointer = Addr(TMyClass.PrintIt);
var
Y: MyTRec;
begin
Y.X := 50;
MyProc(X)(@Y,100);
end.
The const block declares things that are CONSTANT, either it resides in the
CODE block or the DATA block, does not matter. ALL functions reside in the
code block, unless you run an EXE packer or code hider on it, that means
that "AT COMPILE TIME", just like constants, functions are put in a specific
place. Thereby any function, including Methods of classes can be called.
Jeremy
- Next message: Rob Kennedy: "Re: Idea"
- Previous message: Dragon Lord: "Re: Idea"
- In reply to: Rob Kennedy: "Re: Idea"
- Next in thread: Dragon Lord: "Re: Idea"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|