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

Down

The component is not drawn, and that's it ... Find similar branches


Aleksandr   (2001-12-18 13:03) [0]

Dear colleagues!
It took me to create a component. Created by spawning from TGraphicControl. I put on the form - everything is in order, it is visible, but it is not drawn, and that's it ... The code is

type
TWayTree = class (TGraphicControl)
private
.
protected
procedure Paint; override;
public
constructor Create (AOwner: TComponent);
published
.
property Color default clWhite;
property Visible default true;
end;

procedure Register;

implementation

procedure TWayTree.Paint;
was
ARect: TRect;
begin
Inherited;
Canvas.Brush.Color: = Color;
ARect.Left: = Left;
ARect.Top:=Top;
ARect.Bottom: = Top + Height;
ARect.Right: = Left + Width;
Canvas.FillRect (ARect)
end;

constructor TWayTree.Create;
begin
Inherited Create (AOwner);
.
end;

procedure Register;
begin
RegisterComponents ("WayTrees", [TWayTree])
end;

end.

Moreover, when I am still trying to add the FPen and FBrush properties (for separate access in the design time):

TWayTree = class (TGraphicControl)
private
FPen: TPen;
FBrush: TBrush;
procedure RePaintRequest (Sender: TObject);
procedure SetBrush (Value: TBrush);
procedure SetPen (Value: TPen);
protected
procedure Paint; override;
public
constructor Create (AOwner: TComponent);
destructor Destroy;
published
property Color default clWhite;
property Visible;
property Brush: TBrush read FBrush write SetBrush;
property Pen: TPen read FPen write SetPen;
end;

procedure Register;

implementation

procedure TWayTree.Paint;
was
ARect: TRect;
begin
Inherited;
Canvas.Pen: = FPen;
Canvas.Brush: = FBrush;
Canvas.Brush.Color: = Color;
ARect.Left: = Left;
ARect.Top:=Top;
ARect.Bottom: = Top + Height;
ARect.Right: = Left + Width;
Canvas.FillRect (ARect);
Canvas.TextOut (ARect.Left, ARect.Top, "AAA");
end;

destructor TWayTree.Destroy;
begin
FPen.Free;
FBrush.Free;
inherited Destroy
end;

constructor TWayTree.Create;
begin
Inherited Create (AOwner);
FPen: = TPen.Create;
FBrush: = TBrush.Create;
FPen.OnChange: = RepaintRequest;
FBrush.OnChange: = RepaintRequest
end;

procedure TWayTree.SetBrush;
begin
if Value = nil then
Exit;
FBrush.Assign (Value);
Invalidate
end;

procedure TWayTree.SetPen;
begin
if Value = nil then
Exit;
FPen.Assign (Value);
Invalidate
end;

procedure TWayTree.RePaintRequest;
begin
Invalidate
end;

procedure Register;
begin
RegisterComponents ("WayTrees", [TWayTree]);
end;

end.
The component swears when inserted into a form that it can not set the Pen to nil. Pen and Brush appear in the Inspector, but when I click on +, the nifiga does not fall out, when I resize the components, the same error ...



csf   (2001-12-18 13:09) [1]

Restart Delphi, they say, helps.
About Stored you can still read ...



Aleksandr   (2001-12-18 13:11) [2]

Sorry, I have to go to the dump ... I figured out that I forgot to override opposite the constructor with the destructor to draw ... I wonder how you can connect a vertical ScrollBar to this component ...



csf   (2001-12-18 13:19) [3]

... it would be nice to check with Paint FPen & FBrush for nil ...



Юрий Зотов   (2001-12-18 14:30) [4]

> csf

1. > Restart Delphi, they say, helps.
Valuable advice.

2. > You can still read about the stored ...
Can. Only to sabzh it has nothing to do.

3. > ... it would be nice to check with Paint FPen & FBrush for nil ...
What for? They are created in the component constructor. Nil can not be there.

Total: You wrote 3 phrases and all 3, excuse me, nonsense. Was it worth writing? Is it worth it at all to answer questions whose topic you, to put it mildly, are not very familiar with?


> Aleksandr

You have already dealt with override yourself, but that's not all - you have a double redraw:

procedure TWayTree.SetBrush;
begin
if Value = nil then // This is unnecessary and even harmful - it masks the user's mistakes
Exit;
FBrush.Assign (Value); // Generate FBrush.OnChange and call RePaintRequest
Invalidate // This is superfluous - there is a repeated redrawing.
end;

And the same in SetPen. In addition, the ARect variable in Paint is completely unnecessary - use ClientRect or Canvas.ClipRect.

Finally, the main thing - their FBrush and FPen is absolutely useless - only extra resources are being destroyed. Use the built-in Canvas:

published
property Pen: TPen read GetPen write SetPen;
.

function ... GetPen: TPen;
begin
Result: = Canvas.Pen
end;

procedure ... SetPen (const Value: TPen);
begin
Canvas.Pen.Assign (Value)
end;

Conclusion - even such simplest components need to be thought through more carefully and more carefully.



Aleksandr   (2001-12-18 15:50) [5]

2 Yuri Zotov
Thanks for the info. However, a direct reference to the properties of the canvas will cause something that will not be the "standard" by default - it will always continue to draw in the color that was used last. And, accordingly, nothing can be planted on OnChange - an elementary loop will occur - setting the canvas color causes OnChange, it causes a redraw, and in the redraw, the Canvas color changes again.
There is only one question on the agenda: how to pack in the TScrollBar component? Something I can't do double inheritance - from TGraphicControl and from TScrollBar ...



DieHard   (2001-12-18 16:01) [6]

Double inheritance will not work.
Try to inherit from TScrollBox.



MBo   (2001-12-18 16:02) [7]

no double inheritance.
maybe inherit from TWinControl?



Polevi   (2001-12-18 16:19) [8]

TCustomControl



Aleksandr   (2001-12-18 16:19) [9]

Hmm ... well, let's leave this for now ... Here's how to avoid the constant flickering of components when resizing a form?



panov   (2001-12-18 16:31) [10]

> Aleksandr © (18.12.01 16: 19)
Try setting Enabled: = False before resizing



Юрий Зотов   (2001-12-18 17:25) [11]

> Aleksandr © (18.12.01 15: 50)

> it will always continue to draw in the color that was used last.

What is required.


> And, accordingly, nothing can be planted on OnChange

And do not. Your Paint method will be called automatically, and nothing else is required.

> there will be an elementary looping - setting the color of the canvas
> causes OnChange, it causes redrawing, and in redrawing again
> Canvas color changes.

First, you yourself confirm that changing the properties of the canvas automatically calls your Paint method. This means that you have to agree with the previous point - you do not need any OnChange handlers (OnChange handlers only give an extra redraw - hence the extra blink).

Secondly, in the redrawing DO NOT need to change the properties of the canvas. What for? After all, if you tie the properties of the component onto the properties of the canvas, then when you call the Paint method, these properties of the canvas will ALREADY be set as necessary. Draw with them without changing anything. And then there will be no looping.

In general, I advise you to try - see for yourself. I think the flicker will be significantly reduced.

Next, about the flicker and ScrollBar - listen to the advice of Polevi. TCustomControl is a window. ScrollBars are inserted there by simply setting the WS_HSCROLL / WS_VSCROLL styles in CreateParams, and you can reduce the flickering by setting the DoubleBuffered property.



Pages: 1 whole branch

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

Top









Memory: 0.87 MB
Time: 0.034 c
3-21954
strahov
2001-12-05 15:32
2002.01.08
Has anyone met a bug


4-22499
Yus
2001-10-31 20:51
2002.01.08
FindWindow


7-22434
tomas2001
2001-09-24 14:04
2002.01.08
File transfer via modem


3-21986
Dreamer
2001-12-06 15:43
2002.01.08
Data Field not permitted on open DataSet


3-21996
vinni2000
2001-12-06 11:47
2002.01.08
How to select data from Query using a query





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 Español swahili Swedish thai turkish Ukrainian urdu vietnamese welsh yiddish bengali bosnian
cebuano Esperanto gujarati hausa hmong igbo javanese kannada khmer lao latin maori marathi mongolian nepali punjabi somali tamil telugu yoruba
zulu
English French German Italian Portuguese Russian Spanish