Re: Idea

From: Dragon Lord (invalid_at_joke.com)
Date: 02/03/04


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



Relevant Pages

  • Re: Idea
    ... > In Theory, it should compile, Since the included function are apart ... No, the const block declares things that reside in the data segment, not ... initialize those method pointers. ... But stand-alone function pointers don't carry as much information ...
    (comp.lang.pascal.delphi.misc)
  • Re: dynamic types
    ... CodeDom so any pointers on how to use it is helpful. ... ahead of time using CodeDom and then compile them into the assembly that ... versioning to compare the two type descriptions and then only do the real ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: [Bug #11342] Linux 2.6.27-rc3: kernel BUG at mm/vmalloc.c - bisected
    ... Ingo Molnar wrote: ... Doesnt have ... and the full "allyesconfig" does compile. ... only pointers to cpumask's can be passed to functions and returned from ...
    (Linux-Kernel)
  • Re: memmove crash
    ... Pointers and ints are not the same size on all systems. ... system doesn't compile on yours, then I think I definately want to go back to assembly language. ... I can take an assembly program and recompile it on any other x86 linux system and it will compile and work without a problem, whereas if you take a C program that compiles on one person's x86 linux system, it may or may not compile on another's. ... If a program assembles and works on one x86 linux system, it will assemble and work on another x86 linux system just the same. ...
    (alt.lang.asm)
  • [RFC] [PATCH] 32-bit pointers in x86-64
    ... usage due to 64-bit pointers and longs in structures. ... such a GCC version could be used to produce a GNU/Linux ... Compile a native x86-32 libc and compile and test a full Debian or ... emit_move_insn (temp, val); ...
    (Linux-Kernel)