Board index » delphi » Types and Type-casting ...

Types and Type-casting ...

I'm trying to write a procedure that takes in a TComponent and a TFont.

I want to resize the TComponent to reflect the new TFont as in:

procedure Resize(Temp : TComponent; NewFont : TFont);
begin
  if (Temp is TEdit) then begin
    TEdit(Temp).Font := NewFont;
    TEdit(Temp).Width := NewFont.Height*4*TEdit(Temp).MaxLength; {whatever}
    TEdit(Temp).Height := - NewFont.Height + 15;
    { etcetera }
  end
  else if (Temp is TCompoBox) then begin
    TGroupBox(Temp).Font := NewFont;
    .
    .
    .

But there has GOT to a BETTER way to do this!  Is there anyway to extract
the type from a variable?  I doubt it, but I'm groping.  

Or an even better question:  Does anyone have a components that resize
depending on their font and MaxLength property?  I've got TGroupboxes that
I want to resize when their TEdit and TGroupBox "members" ("controls") change.

Any suggestions?  

Thanks a 10^6 in advance!

jP

--
----------------- Jon A. Preston  (gt50...@acme.gatech.edu) -----------------
 "If a man remains in me and I in him, he will bear much fruit." - John 15:5

 

Re:Types and Type-casting ...


Quote

>But there has GOT to a BETTER way to do this!  Is there anyway to extract
>the type from a variable?  I doubt it, but I'm groping.  

You can use the RTTI to do this better.

Quote

>Or an even better question:  Does anyone have a components that resize
>depending on their font and MaxLength property?  I've got TGroupboxes that
>I want to resize when their TEdit and TGroupBox "members" ("controls") change.

>Any suggestions?  

I would look into the TLabel field.  It resizes itself based on the text
length and font.

--
************************************
*           The Nomad              *
*        tno...@digital.net        *
************************************

Re:Types and Type-casting ...


Quote
The Nomad (tno...@digital.net) wrote:

: You can use the RTTI to do this better.

Can you expound on this?  What is RTTI?

: >
: >Or an even better question:  Does anyone have a components that resize
: >depending on their font and MaxLength property?  I've got TGroupboxes that
: >I want to resize when their TEdit and TGroupBox "members" ("controls") change.

: I would look into the TLabel field.  It resizes itself based on the text
: length and font.

But the idea is to have the niceities of a TGroupBox.

Thanks.

jP

--
----------------- Jon A. Preston  (gt50...@acme.gatech.edu) -----------------
 "If a man remains in me and I in him, he will bear much fruit." - John 15:5

Re:Types and Type-casting ...


Quote

>Can you expound on this?  What is RTTI?

RTTI is Run Time Type Information.  I found out about it through only
after posting a similar question back in April (thanks Duncan).  Hey -
that's what makes the net wonderful.  Anyway, in the
delphi\doc\typinfo.int file you will see functions that read info from
the RTTI table.

There should be a tip posted at :

http://www.mindspring.com/~cityzoo/tips/tips.html

************************************
*           The Nomad              *
*        tno...@digital.net        *
************************************

Other Threads