Top.Mail.Ru Yandeks.Metrika
Forum: "Main";
Current archive: 2003.05.01;
Download: [xml.tar.bz2];


How to change form properties from your non-visual component Find similar branches

Мыш   (2003-04-18 17:25) [0]

I throw the component onto the form, made it based on tcomponent, the code is very simple, it just changes the color according to the created timer, the form looks, etc. I train.

How to get to the properties of the form on which I threw my component?
I tried this:
1. in the constructor
tform (aowner) .Caption: = "asdf";

2 in private:
ftm: ^ tcomponent;
in the constructor:
ftm: = @ aowner;

then I really don’t know what to do with this pointer

3.in private:
function GetForm: TForm;
property Form: TForm read GetForm;

further in implementation:

function TFormPos.GetForm: TForm;
if Owner is TCustomForm then Result: = TForm (Owner as TCustomForm)
else Result: = nil;

further in any procedure:
GetForm.Caption: = "asfdd";

Everywhere gives access violation

MBo   (2003-04-18 17:28) [1]

1) ^ and @ is not necessary.
2) not Owner, but Parent
3) read a lot of books and help

Игорь Шевченко   (2003-04-18 17:28) [2]

ValidParentForm (AControl: TControl): TCustomForm

MBo   (2003-04-18 17:30) [3]

sorry, my second point is incorrect - the component is non-visual

Skier   (2003-04-18 17:34) [4]

> Mouse
override do you write for your constructor?

мыш   (2003-04-18 17:43) [5]

I am writing override. Help read, read the source, as usual I didn’t understand anything :) Well, I'm not really stupid, I just understood what a class is a couple of days ago, when I pulled myself together and read the entire hierarchy from Tobject to Tform. And the component has already done! And only one moment does not work - it's a shame, but I want everything at once :)

For example, it’s not clear why the function
function TFormPos.GetForm: TForm;
if Owner is TCustomForm then Result: = TForm (Owner as TCustomForm)
else Result: = nil;
it doesn’t give the correct link to the ancestor form in order to write getform.widht: = ... because I stole it from rxlib, and this way it works.

мыш   (2003-04-18 17:46) [6]

2 Igor Shevchenko: and whom should I pass in the parameter? I don’t know how a particular component instance will be called.

Skier   (2003-04-18 17:48) [7]

> mouse
Component code in the studio!

мыш   (2003-04-18 18:10) [8]

unit FormPos;


Windows, Messages, SysUtils, Classes, QExtCtrls, forms, QForms,
Variants, Controls,
Dialogs, ExtCtrls, StdCtrls;

type TFormPosition = (fpLeft, fpRight, fpTop, fpBottom, fpCenter);

TFormPos = class (TComponent)

TimCheckMouse: TTimer;
FInfoPanel: Tpanel;

FormPosition: TFormPosition;
AllowMoveMessage: boolean;

FActive: boolean;
FFormWidth: integer;
FMyOwner: string;

function GetForm: Tcustomform;
function SetGetFormWidth: integer;
function GetMyOwner: string;

{Private declarations}
procedure TimCheckMouseTimer (sender: tobject);
procedure SetFormPos (aFormPos: TformPosition);
procedure wmmove (var mess: twmmove); message wm_move;

property Form: Tcustomform read GetForm;

{Protected declarations}
constructor create (Aowner: Tcomponent); override;
{Public declarations}
property IsActive: Boolean read Factive write FActive default true;
property FormWidth: integer read SetGetFormWidth;
property MyOwner: string read GetMyOwner;
{Published declarations}

procedure Register;


procedure Register;
RegisterComponents ("Additional", [TFormPos]);


constructor TFormPos.create (Aowner: Tcomponent);
inherited Create (AOwner);

//tform(aowner).Caption:="asdf ";

TimCheckMouse: = TTimer.Create (self);
TimCheckMouse.Interval: = 100;
TimCheckMouse.OnTimer: = TimCheckMouseTimer;

function TFormPos.GetForm: Tcustomform;
if Owner is TForm then Result: = TCustomForm (Owner)
else Result: = nil;

procedure TFormPos.wmmove (var mess: twmmove);
if not AllowMoveMessage then
AllowMoveMessage: = true;
FormPosition: = fpcenter;
if mess.XPos <16 then FormPosition: = fpLeft;
if mess.XPos + GetForm.width> screen.Width-16 then FormPosition: = fpRight;
if mess.YPos <32 then FormPosition: = fpTop;
if mess.YPos + GetForm.height> screen.Height-32 then FormPosition: = fpBottom;
SetFormPos (FormPosition);
//GetForm.caption:="mv"+floattostr(mess.XPos)+ "" + floattostr (mess.yPos);

procedure TFormPos.SetFormPos (aFormPos: TFormPosition);

case aFormPos of
GetForm.Left: = 0;
GetForm.Left: = screen.Width-GetForm.width;

procedure TFormPos.TimCheckMouseTimer (sender: tobject);
x, y: integer;
if not IsActive then exit;
x: = mouse.CursorPos.X;
Y: = mouse.CursorPos.Y;

if x <32 then setformpos (fpleft);
if x <screen.Width-getform.Width-32 then setformpos (fpright);
if y <32 then setformpos (fptop);
if y> screen.Height-getform.Height-32 then setformpos (fpbottom);


function TFormPos.SetGetFormWidth: integer;
result: = twincontrol (owner) .Width;

function TFormPos.GetMyOwner: string;
result: = (owner as tpersistent) .GetNamePath


Skier   (2003-04-18 18:16) [9]

This is suspicious!
procedure wmmove (var mess: twmmove); message wm_move;
Why is it ?!

мыш   (2003-04-18 18:17) [10]

to fix the movement of the form and immediately make changes

Мыш   (2003-04-19 12:10) [11]


Юрий Зотов   (2003-04-19 12:49) [12]

> procedure wmmove (var mess: twmmove); message wm_move;
> to record the movement of the form and immediately make changes

This is how your component will receive such a message? And from whom?

As you say yourself, only a couple of days ago you realized what a class is (by the way, are you sure of that?) And read the VCL hierarchy right up to TForm. But WHY this hierarchy is built in exactly this way, and not otherwise, what ESSENCE и PURPOSE: every class in it, HOW these classes interact with Windows - did you understand that too?

I'm afraid not. Otherwise, a method would never appear in your component that would never be called by anyone. And if so, is it not too early for you to write components?

The fact is that, without understanding even the ABC (!!!) that I mentioned above, there is nothing even to think about writing components. This is not serious.

Try to find Konopka’s book. Having read and UNDERSTANDING her, you will laugh for a long time at this your first "component".

мыш   (2003-04-19 14:10) [13]

As for wm_move, I already realized that it was a mistake, because only windows receive this message.
A class is such a collection of properties and procedures for processing them and other data. Tobject is a base class that is responsible for allocating memory, allocating it for a newly created instance, freeing up and other basic things. Each new class should be built on an existing one, so as not to write what is already written by the Borland programmers. Each class receives messages from Windows, for example, only windows receive mousedown, etc., process these messages. You can override the processing of messages and procedures of the ancestor class.
Here is a brief summary of everything I know. Do you still think it's too early for me to write a component?
By the way, I believe that nothing is never too early, if there is a desire, it will do for any reason. For example, I would never have climbed into these classes in a help if I hadn’t been so ambitious and started writing a component.
And I can’t afford to buy a book ... :( But thanks for the advice on the author.

vuk   (2003-04-19 14:27) [14]

to mouse:
If your component only works with the TCustomForm successor as the owner, then why not forbid it to “live” somewhere other than the form? It is done simply:
Step 1. Verification in the constructor. If the owner is unsuitable - exception.
Step 2. Override ValidateContainer. If the container is unsuitable - exception.

Then type checks will not be needed every time a form is needed.

Юрий Зотов   (2003-04-19 14:59) [15]

> Each class receives messages from Windows

No. Messages from Windows get ONLY window. And that’s all. More NO ONE VCL class no messages from Windows do not get. Already if only because Windows has no clue about any VCL or any of its classes. Even the descendants of TWinControl. She knows ONLY the windows themselves, but not the VCL objects that encapsulate them. Moreover, she does not know everything else.

Another thing is that in VCL there is an internal broadcast of messages (Dispatch, Perform methods, etc.) - but this is already Broadcast rather than directly receiving messages from SYSTEMS .

> Do you still think it's too early for me to write a component

VCL has a hierarchical sub-chain like this:

TObject TPersistent TComponent TControl Twincontrol TCustomControl TGraphicControl

Answer yourself the following questions:

- what is it needed for EACH of these classes what is it ESSENCE and for what SPECIFICALLY he answers;

- which appear in it MAIN properties, methods and events, and why they appear EXACTLY in him;

- which of these new methods are static, which are dynamic, which are virtual, which are abstract, and which are class and WHY ;

- which of these new properties (and events) are declared in the protected section, which are in public, and which are in published (and WHY );

- which of these classes have the corresponding metaclass and WHAT FOR this metaclass is needed;

- From WHOM и HOW can receive messages EACH of these classes, WHERE he can process them and WHAT FOR he needs them.

So: as soon as you can answer these questions with a full understanding of their essence and NEVER LOOKING - so you are ready to start writing NORMAL components (rather than crafts that you can either cry or laugh at, but nothing more can be done with them).

Because for NORMAL Component Writer "and all these questions are just more ABC . The necessary minimum. And the rest will come with experience.

Pages: 1 whole branch

Forum: "Main";
Current archive: 2003.05.01;
Download: [xml.tar.bz2];


Memory: 0.63 MB
Time: 0.03 c
2003-03-07 07:58

2003-03-06 15:20
TWebBrowser - prohibit opening a new window on the hyperlink

2003-04-18 10:42
block size is a multiple of the file size. eof not working.

2003-04-14 08:44
Sort table

2003-04-20 20:05

afrikaans albanian Arabic armenian azerbaijani basque belarusian bulgarian catalan Chinese (Simplified) Chinese (Traditional) croatian Czech danish Dutch English estonian filipino finnish French
galician georgian German greek haitian Creole hebrew Hindi hungarian icelandic Indonesian Irish italian Japanese Korean latvian lithuanian macedonian malay maltese norwegian
persian polish portuguese Romanian russian serbian slovak Slovenian Spanish swahili Swedish ภาษาไทย turkish Ukrainian urdu Tiếng Việt welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada Khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
English French German Italian Portuguese Russian Spanish