List Info

Thread: final question on TMethod and similar




final question on TMethod and similar
user name
2006-05-16 22:23:33
> type TP = procedure(a : integer) of object;
> type P_TP = ^TP;
>
> procedure TForm1.Button1Click(Sender: TObject);
> var
>    ParamMethod : TArrayOfPointers;
>    m : procedure(a : integer) of object;

Since you have declared a type name for that, go ahead and use it:

var
  m: TP;

>;    a : integer;
>    m1 : Pointer;
> begin
>;    App(0);
>    m := App;
>  ;  m1 := m;
>    a := 1027;
>;
>    m(0);
>;
>    P_TP(m1)^(3);

M1 is a Pointer. It currently points to something of type TP, which means
that its real type should be declared as P_TP. (When you declare things
with typed pointers instead of just Pointer, you can remove a lot of
type-casts, and then the compiler can help you find errors.)

When you say "m1", you get a pointer to that variable, so you get a value
of type P_P_TP. That's not the same as a P_TP, so it's not valid to
type-cast it like that.

M1 is already holding a P_TP, so type-cast it directly:

P_TP(m1)^(3);

> end;
>
> procedure TForm1.App(a : integer);
> var pSelf : Pointer;
> begin
>;    pSelf := Self;
>;
>&nbsp; &nbsp; if (Self.Height < 543) or (pSelf = Pointer(52)) then

What's with 52? I'm quite certain pSelf's value will never be 52 in a
valid program.

; &nbsp; &nbsp;  Self.Height := Self.Height div 2;
> end;
>
>
>; generates an exception in  the call "P_TP(m1)^(3);&quot;

I'm not really sure what you're trying to do, but it's almost certainly
not the right way to do it. Please explain what task you're trying to
accomplish instead of just showing us glimpses of your attempted solution.

--
Rob


final question on TMethod and similar
user name
2006-05-17 10:16:20
pointers - id rather use procedural types and assign and call without
touching pointers. what are you trying to achieve (the big picture)?

Rob Kennedy wrote:
&gt; Mauro Russo wrote:
&gt;> type TP = procedure(a : integer) of object;
&gt;> type P_TP = ^TP;
>>
>&gt; procedure TForm1.Button1Click(Sender: TObject);
>> var
>&gt; &nbsp;  ParamMethod : TArrayOfPointers;
&gt;> ; &nbsp; m : procedure(a : integer) of object;
&gt;
> Since you have declared a type name for that, go ahead and use it:
>
> var
>&nbsp;  m: TP;
>
>>  ;  a : integer;
>>&nbsp; &nbsp; m1 : Pointer;
>> begin
>;>   ; App(0);
&gt;>&nbsp; &nbsp; m := App;
>> &nbsp;  m1 := m;
>&gt; &nbsp;  a := 1027;
>;>
>> &nbsp;  m(0);
>;>
>> &nbsp;  P_TP(m1)^(3);
>
> M1 is a Pointer. It currently points to something of type TP, which means
>; that its real type should be declared as P_TP. (When you declare things
&gt; with typed pointers instead of just Pointer, you can remove a lot of
> type-casts, and then the compiler can help you find errors.)
>
> When you say "m1", you get a pointer to that variable, so you get a value
>; of type P_P_TP. That's not the same as a P_TP, so it's not valid to
> type-cast it like that.
>;
> M1 is already holding a P_TP, so type-cast it directly:
>
> P_TP(m1)^(3);
>
>> end;
>>
>&gt; procedure TForm1.App(a : integer);
>> var pSelf : Pointer;
>> begin
>;>   ; pSelf := Self;
>;>
>> &nbsp;  if (Self.Height < 543) or (pSelf = Pointer(52)) then
>
> What's with 52? I'm quite certain pSelf's value will never be 52 in a
> valid program.
>
>>  ; &nbsp; &nbsp; Self.Height := Self.Height div 2;
>&gt; end;
>>
>&gt;
>&gt; generates an exception in  the call "P_TP(m1)^(3);&quot;
>
> I'm not really sure what you're trying to do, but it's almost certainly
> not the right way to do it. Please explain what task you're trying to
> accomplish instead of just showing us glimpses of your attempted solution.
>
[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )