Programlama yapalım ve Öğrenelim. - Delphi Eğitim166
  Ana Sayfa
  .NET Eğitim Notları
  Visual C# .NET Örnek Kodları
  VisualBasic.NET Örnek Kodları
  J# Örnekleri
  ASP.NET Örnek Kodları
  Delphi Eğitim
  => Delphi Eğitim1
  => Delphi Eğitim2
  => Delphi Eğitim3
  => Delphi Eğitim4
  => Delphi Eğitim5
  => Delphi Eğitim6
  => Delphi Eğitim7
  => Delphi Eğitim8
  => Delphi Eğitim9
  => Delphi Eğitim10
  => Delphi Eğitim11
  => Delphi Eğitim13
  => Delphi Eğitim14
  => Delphi Eğitim15
  => Delphi Eğitim16
  => Delphi Eğitim17
  => Delphi Eğitim18
  => Delphi Eğitim19
  => Delphi Eğitim20
  => Delphi Eğitim21
  => Delphi Eğitim22
  => Delphi Eğitim23
  => Delphi Eğitim24
  => Delphi Eğitim25
  => Delphi Eğitim26
  => Delphi Eğitim27
  => Delphi Eğitim28
  => Delphi Eğitim29
  => Delphi Eğitim30
  => Delphi Eğtim31
  => Delphi Eğitim32
  => Delphi Eğitim33
  => Delphi Eğitim34
  => Delphi Eğitim35
  => Delphi Eğitim36
  => Delphi Eğitim37
  => Delphi Eğitim38
  => Delphi Eğitim39
  => Delphi Eğitim40
  => Delphi Eğitim41
  => Delphi Eğitim42
  => Delphi Eğitim43
  => Delphi Eğitim44
  => Delphi Eğitim45
  => Delphi Eğitim46
  => Delphi Eğitim47
  => Delphi Eğitim48
  => Delphi Eğitim49
  => Delphi Eğitim50
  => Delphi Eğitim51
  => Delphi Eğitim52
  => Delphi Eğitim53
  => Delphi Eğitim54
  => Delphi Eğitim55
  => Delphi Eğitim56
  => Delphi Eğitim57
  => Delphi Eğitim58
  => Delphi Eğitim59
  => Delphi Eğitim60
  => Delphi Eğitim61
  => Delphi Eğitim62
  => Delphi Eğitim63
  => Delphi Eğitim64
  => Delphi Eğitim65
  => Delphi Eğitim66
  => Delphi Eğitim67
  => Delphi Eğitim68
  => Delphi Eğitim69
  => Delphi Eğitim70
  => Delphi Eğitim71
  => Delphi Eğitim72
  => Delphi Eğitim73
  => Delphi Eğitim74
  => Delphi Eğitim75
  => Delphi Eğitim76
  => Delphi Eğitim77
  => Delphi Eğitim78
  => Delphi Eğitim79
  => Delphi Eğitim80
  => Delphi Eğitim81
  => Delphi Eğitim82
  => Delphi Eğitim83
  => Delphi Eğitim84
  => Delphi Eğitim85
  => Delphi Eğitim86
  => Delphi Eğitim87
  => Delphi Eğitim88
  => Delphi Eğitim89
  => Delphi Eğitim90
  => Delphi Eğitim91
  => Delphi Eğitim92
  => Delphi Eğitim93
  => Delphi Eğitim94
  => Delphi Eğitim95
  => Delphi Eğitim96
  => Delphi Eğitim97
  => Delphi Eğitim98
  => Delphi Eğitim99
  => Delphi Eğitim100
  => Delphi Eğitim101
  => Delphi Eğitim102
  => Delphi Eğitim103
  => Delphi Eğitim104
  => Delphi Eğitim105
  => Delphi Eğitim106
  => Delphi Eğitim107
  => Delphi Eğitim108
  => Delphi Eğitim109
  => Delphi Eğitim110
  => Delphi Eğitim111
  => Delphi Eğitim112
  => Delphi Eğitim113
  => Delphi Eğitim114
  => Delphi Eğitim115
  => Delphi Eğitim116
  => Delphi Eğitim117
  => Delphi Eğitim118
  => Delphi Eğitim119
  => Delphi Eğitim120
  => Delphi Eğitim121
  => Delphi Eğitim122
  => Delphi Eğitim123
  => Delphi Eğitim124
  => Delphi Eğitim125
  => Delphi Eğitim126
  => Delphi Eğitim127
  => Delphi Eğitim128
  => Delphi Eğitim129
  => Delphi Eğitim130
  => Delphi Eğitim131
  => Delphi Eğitim132
  => Delphi Eğitim133
  => Delphi Eğitim134
  => Delphi Eğitim135
  => Delphi Eğitim136
  => Delphi Eğitim137
  => Delphi Eğitim138
  => Delphi Eğitim139
  => Delphi Eğitim140
  => Delphi Eğitim141
  => Delphi Eğitim142
  => Delphi Eğitim143
  => Delphi Eğitim144
  => Delphi Eğitim145
  => Delphi Eğitim146
  => Delphi eğitim147
  => Delphi Eğitim148
  => Delphi Eğitim149
  => Delphi Eğitim150
  => Delphi Eğitim151
  => Delphi Eğitim152
  => Delphi Eğitim153
  => Delphi Eğitim154
  => Delphi Eğitim155
  => Delphi Eğitim156
  => Delphi Eğitim157
  => Delphi Eğitim158
  => Delphi Eğitim159
  => Delphi Eğitim160
  => Delphi Eğitim161
  => Delphi Eğitim162
  => Delphi Eğitim164
  => Delphi Eğitim165
  => Delphi Eğitim166
  => Delphi Eğitim167
  => Delphi Eğitim168
  => Delphi Eğitim169
  => Delphi Eğitim170
  => Delphi Eğitim171
  => Delphi Eğitim172
  => Delphi Eğitim173
  => Delphi Eğitim174
  => Delphi Eğitim175
  => Delphi Eğitim176
  => Delphi Eğitim177
  => Delphi Eğitim178
  => Delphi Eğitim179
  => Delphi Eğitim180
  => Delphi Eğitim181
  => Delphi Eğitim182
  => Delphi Eğitim183
  => Delphi Eğitim184
  => Delphi Eğitim185
  => Delphi Eğitim186
  => Delphi Eğitim187
  => Delphi Eğitim188
  => Delphi Eğitim189
  => Delphi Eğitim190
  => Delphi Eğitim191
  => Delphi Eğitim192
  => Delphi Eğitim193
  => Delphi Eğitim194
  => Delphi Eğitim195
  => Delphi Eğitim196
  => Delphi Eğitim197
  => Delphi Eğitim198
  => Delphi Eğitim199
  => Delphi Eğitim200
  => Delphi Eğitim201
  => Delphi Eğitim202
  => Delphi Eğitim203
  => Delphi Eğitim204
  => Delphi Eğitim205
  => Delphi Eğitim206
  => Delphi Eğitim207
  => Delphi Eğitim208
  => Delphi Eğitim209
  => Delphi Eğitim210
  => Delphi Eğitim211
  => Delphi Eğitim212
  => Delphi Eğitim213
  => Delphi Eğitim214
  => Delphi Eğitim215
  => Delphi Eğitim216
  => Delphi Eğitim217
  => Delphi Eğitim218
  => Delphi Eğitim219
  => Delphi Eğitim220
  => Delphi Eğitim221
  => Delphi Eğitim222
  => Delphi Eğitim223
  => Delphi Eğitim224
  => Delphi Eğitim225
  => Delphi Eğitim226
  => Delphi Eğitim227
  => Delphi Eğitim228
  => Delphi Eğitim229
  => Delphi Eğitim230
  => Delphi Eğitim231
  => Delphi Eğitim232
  => Delphi Eğitim233
  => Delphi Eğitim234
  => Delphi Eğitim235
  => Delphi Eğitim236
  => Delphi Eğitim237
  => Delphi Eğitim238
  => Delphi Eğitim239
  => Delphi Eğitim240
  => Delphi Eğitim241
  => Delphi Eğitim242
  İletişim

neoturk: ...Change a hint's font ?...

{

  When the application displays a Help Hint,

  it creates an instance of HintWindowClass to represent

  the window used for displaying the hint.

  Applications can customize this window by creating a

  descendant of THintWindow and assigning it to the

  HintWindowClass variable at application startup.

}

 

type

  TMyHintWindow = class(THintWindow)

    constructor Create(AOwner: TComponent); override;

  end;

 

 

implementation

 

{....}

 

constructor TMyHintWindow.Create(AOwner: TComponent);

begin

  inherited Create(AOwner);

  with Canvas.Font do

  begin

    Name := 'Arial';

    Size := Size + 5;

    Style := [fsBold];

  end;

end;

 

procedure TForm2.FormCreate(Sender: TObject);

begin

  HintWindowClass := TMyHintWindow;

  Application.ShowHint := False;

  Application.ShowHint := True;

end;

 

Delphi - .....................................

 

neoturk: ...Use the tools menu in the ide ?...

The menu "Tools" is a free configurable part of the Delphi-IDE.

You can there insert tools, you often use while coding.

I (for example) have the MSDN and another Editor in there.

First choose Tools / Configure Tools. Then click Add, to add another item.

Title is the caption beeing showed, when you open the tools menu.

A & makes the next letter to the QuickSelect letter.

Program is the program, you want to launch.

Use here (for example) "C:Program FilesTextPadTextPad.exe".

If you have spaces in you path or filename, quote the hole string.

Working dir is the directory, the program will be launched.

It's normally the same as the program directory.

Parameters are beeing given to the program, you run, or (in case of macros) are beeing run,

when you select the item. Click on parameters, to show a list of macros for use with it.

With a second editor, the macros $SAVEALL and $NAME will be usefull.

To make the menu more structured, you can use a horizontal rule.

You create one, by entering - in the Title field.

Cause of a bug in the Delphi IDE, you cannot create a second rule as easy.

You'll have to enter another caption first and then rename it.

 

{***************************************************************************}

 

Das Tools Menu ist ein frei konfigurierbarer Teil der Delphi-IDE.

Man kann darin Programme, die man oft zur Entwicklung von Delphi-Programmen braucht konfigurieren,

um sie bei Bedarf schneller zu öffnen.

Ich habe dort drin z.B. die MSDN und ein alternativer Editor für Delphi-Sources, sowie einige andere Tools.

Zuerst wählt man Tools / Configure Tools. In dem dann erscheinenden Menu kann man per

Add neue Einträge hinzufügen.

Unter Title gibt man den Namen an, der erscheinen soll. '&' unterstreicht den nächsten Buchstaben

(QuickSelect).

Unter Programm gibt man das Programm an, welches man starten möchte.

Z.B. C:ProgrammeTextPadTextPad.exe. Wenn der Pfad Leerzeichen enthält,

muss man entweder alles ins 8.3-Format konvertieren, oder den Pfad mit "" schreiben.

Unter Working Dir sollte man den Pfad angeben, in dem auch das Programm ist.

Unter Parameters kann man Makros sowie auch Parameter für das Programm hinzufügen.

Mit einem Klick auf Macros öffnet sich eine Liste mit den vorhandenen Makros mit kurzer Beschreibung.

Für einen zweiten Editor währe z.B. $SAVEALL, sowie $NAME sehr nützlich.

Um das ganze Menu besser Strukturieren zu können, können Horizontale Linien angelegt werden.

Dies macht man mit einem neuen Item, dass unter Title einen - (Bindestrich) drin hat.

Leider hat es in Delphi einen Bug, der verhindert, dass man zwei mal das "selbe" Item anlegt.

Um noch eine zweite Linie zu erstellen, muss man zuerst einen anderen Namen nehmen (z.B. Temp)

und dann unter Edit das auf - ändern.

 

Delphi - .....................................

 

neoturk: ...Use the tools menu in the ide ?...

The menu "Tools" is a free configurable part of the Delphi-IDE.

You can there insert tools, you often use while coding.

I (for example) have the MSDN and another Editor in there.

First choose Tools / Configure Tools. Then click Add, to add another item.

Title is the caption beeing showed, when you open the tools menu.

A & makes the next letter to the QuickSelect letter.

Program is the program, you want to launch.

Use here (for example) "C:Program FilesTextPadTextPad.exe".

If you have spaces in you path or filename, quote the hole string.

Working dir is the directory, the program will be launched.

It's normally the same as the program directory.

Parameters are beeing given to the program, you run, or (in case of macros) are beeing run,

when you select the item. Click on parameters, to show a list of macros for use with it.

With a second editor, the macros $SAVEALL and $NAME will be usefull.

To make the menu more structured, you can use a horizontal rule.

You create one, by entering - in the Title field.

Cause of a bug in the Delphi IDE, you cannot create a second rule as easy.

You'll have to enter another caption first and then rename it.

 

{***************************************************************************}

 

Das Tools Menu ist ein frei konfigurierbarer Teil der Delphi-IDE.

Man kann darin Programme, die man oft zur Entwicklung von Delphi-Programmen braucht konfigurieren,

um sie bei Bedarf schneller zu öffnen.

Ich habe dort drin z.B. die MSDN und ein alternativer Editor für Delphi-Sources, sowie einige andere Tools.

Zuerst wählt man Tools / Configure Tools. In dem dann erscheinenden Menu kann man per

Add neue Einträge hinzufügen.

Unter Title gibt man den Namen an, der erscheinen soll. '&' unterstreicht den nächsten Buchstaben

(QuickSelect).

Unter Programm gibt man das Programm an, welches man starten möchte.

Z.B. C:ProgrammeTextPadTextPad.exe. Wenn der Pfad Leerzeichen enthält,

muss man entweder alles ins 8.3-Format konvertieren, oder den Pfad mit "" schreiben.

Unter Working Dir sollte man den Pfad angeben, in dem auch das Programm ist.

Unter Parameters kann man Makros sowie auch Parameter für das Programm hinzufügen.

Mit einem Klick auf Macros öffnet sich eine Liste mit den vorhandenen Makros mit kurzer Beschreibung.

Für einen zweiten Editor währe z.B. $SAVEALL, sowie $NAME sehr nützlich.

Um das ganze Menu besser Strukturieren zu können, können Horizontale Linien angelegt werden.

Dies macht man mit einem neuen Item, dass unter Title einen - (Bindestrich) drin hat.

Leider hat es in Delphi einen Bug, der verhindert, dass man zwei mal das "selbe" Item anlegt.

Um noch eine zweite Linie zu erstellen, muss man zuerst einen anderen Namen nehmen (z.B. Temp)

und dann unter Edit das auf - ändern.

 

Delphi - .....................................

 

neoturk: ...Create a sizable and none border style form ?...

{

  With this code you can create none border style (BorderStyle = bsNone)

  but sizeable windows (forms)

  First you must set BorderStyle := bsNone of your Form in Object Browser.

  There is your small but forced code;

}

 

type

  TForm1 = class(TForm)

  private

    { Private declarations }

  public

    { Public declarations }

    procedure CreateParams(var Params: TCreateParams); override;

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

procedure TForm1.CreateParams(var Params: TCreateParams);

begin

  inherited CreateParams(Params);

  Params.Style := (Params.Style or WS_THICKFRAME);

end;

 

Delphi - .....................................

 

neoturk: ...Create a sizable and none border style form ?...

{

  With this code you can create none border style (BorderStyle = bsNone)

  but sizeable windows (forms)

  First you must set BorderStyle := bsNone of your Form in Object Browser.

  There is your small but forced code;

}

 

type

  TForm1 = class(TForm)

  private

    { Private declarations }

  public

    { Public declarations }

    procedure CreateParams(var Params: TCreateParams); override;

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

procedure TForm1.CreateParams(var Params: TCreateParams);

begin

  inherited CreateParams(Params);

  Params.Style := (Params.Style or WS_THICKFRAME);

end;

 

Delphi - .....................................

 

neoturk: ...Correct a bidi bug in delphi ?...

{

  When you set the BiDiMode in you form to bdRightToLeft, you do only HALF mirroring.

 

  Since Win98 (Hebrew/Arabic version) mirror it's envirement completly

 (the Minimize, Close, Maxmize buttons are on the Left, and the Icon is on the right).

  How can we do it in delphi ?

}

 

{...}

const

 WS_EX_LAYOUTRTL = $00400000;

 WS_EX_LAYOUT_RTL = WS_EX_LAYOUTRTL;

 

{...}

 

 TForm1 = class(TForm)

    procedure FormCreate(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

    procedure CreateParams(var Params : TCreateParams); override;

  end;

 

{...}

 

implementation

 

procedure TForm1.CreateParams(var Params : TCreateParams);

begin

  inherited CreateParams(Params);

  Params.ExStyle := WS_EX_LEFT or WS_EX_RTLREADING or WS_EX_LEFTSCROLLBAR or WS_EX_LAYOUT_RTL;

 {WS_EX_LEFT to set the text caption to the right,

  use WS_EX_RIGHT to set the caption to the left}

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

 BiDiMode := bdLeftToRight; //A must !!!

end;

 

{The result is Right to Left (including the buttons, the icon and the system menu) }

 

Delphi - .....................................

 

neoturk: ...Correct a bidi bug in delphi ?...

{

  When you set the BiDiMode in you form to bdRightToLeft, you do only HALF mirroring.

 

  Since Win98 (Hebrew/Arabic version) mirror it's envirement completly

 (the Minimize, Close, Maxmize buttons are on the Left, and the Icon is on the right).

  How can we do it in delphi ?

}

 

{...}

const

 WS_EX_LAYOUTRTL = $00400000;

 WS_EX_LAYOUT_RTL = WS_EX_LAYOUTRTL;

 

{...}

 

 TForm1 = class(TForm)

    procedure FormCreate(Sender: TObject);

  private

    { Private declarations }

  public

    { Public declarations }

    procedure CreateParams(var Params : TCreateParams); override;

  end;

 

{...}

 

implementation

 

procedure TForm1.CreateParams(var Params : TCreateParams);

begin

  inherited CreateParams(Params);

  Params.ExStyle := WS_EX_LEFT or WS_EX_RTLREADING or WS_EX_LEFTSCROLLBAR or WS_EX_LAYOUT_RTL;

 {WS_EX_LEFT to set the text caption to the right,

  use WS_EX_RIGHT to set the caption to the left}

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

 BiDiMode := bdLeftToRight; //A must !!!

end;

 

{The result is Right to Left (including the buttons, the icon and the system menu) }

 

Delphi - .....................................

 

neoturk: ...Create a transparent tform ?...

private

    { Private declarations }

    FullRgn, ClientRgn, CtlRgn: THandle;

    procedure MakeTransparent;

    procedure UndoTransparent;

  end;

 

{...}

 

implementation

 

{...}

 

procedure TForm1.MakeTransparent;

var

  AControl: TControl;

  A, Margin, X, Y, CtlX, CtlY: Integer;

begin

  Margin    := (Width - ClientWidth) div 2;

  FullRgn   := CreateRectRgn(0, 0, Width, Height);

  X         := Margin;

  Y         := Height - ClientHeight - Margin;

  ClientRgn := CreateRectRgn(X, Y, X + ClientWidth, Y + ClientHeight);

  CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF);

  for A := 0 to ControlCount - 1 do

  begin

    AControl := Controls[A];

    if (AControl is TWinControl) or (AControl is TGraphicControl) then with AControl do

      begin

        if Visible then

        begin

          CtlX   := X + Left;

          CtlY   := Y + Top;

          CtlRgn := CreateRectRgn(CtlX, CtlY, CtlX + Width, CtlY + Height);

          CombineRgn(FullRgn, FullRgn, CtlRgn, RGN_OR);

        end;

      end;

  end;

  SetWindowRgn(Handle, FullRgn, True);

end;

 

procedure TForm1.UndoTransparent;

begin

  FullRgn := CreateRectRgn(0, 0, Width, Height);

  CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);

  SetWindowRgn(Handle, FullRgn, True);

end;

 

// Test it:

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  MakeTransparent

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  UndoTransparent

end;

 

Delphi - .....................................

 

neoturk: ...Create a transparent tform ?...

private

    { Private declarations }

    FullRgn, ClientRgn, CtlRgn: THandle;

    procedure MakeTransparent;

    procedure UndoTransparent;

  end;

 

{...}

 

implementation

 

{...}

 

procedure TForm1.MakeTransparent;

var

  AControl: TControl;

  A, Margin, X, Y, CtlX, CtlY: Integer;

begin

  Margin    := (Width - ClientWidth) div 2;

  FullRgn   := CreateRectRgn(0, 0, Width, Height);

  X         := Margin;

  Y         := Height - ClientHeight - Margin;

  ClientRgn := CreateRectRgn(X, Y, X + ClientWidth, Y + ClientHeight);

  CombineRgn(FullRgn, FullRgn, ClientRgn, RGN_DIFF);

  for A := 0 to ControlCount - 1 do

  begin

    AControl := Controls[A];

    if (AControl is TWinControl) or (AControl is TGraphicControl) then with AControl do

      begin

        if Visible then

        begin

          CtlX   := X + Left;

          CtlY   := Y + Top;

          CtlRgn := CreateRectRgn(CtlX, CtlY, CtlX + Width, CtlY + Height);

          CombineRgn(FullRgn, FullRgn, CtlRgn, RGN_OR);

        end;

      end;

  end;

  SetWindowRgn(Handle, FullRgn, True);

end;

 

procedure TForm1.UndoTransparent;

begin

  FullRgn := CreateRectRgn(0, 0, Width, Height);

  CombineRgn(FullRgn, FullRgn, FullRgn, RGN_COPY);

  SetWindowRgn(Handle, FullRgn, True);

end;

 

// Test it:

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  MakeTransparent

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  UndoTransparent

end;

 

Delphi - .....................................

 

neoturk: ...Check if a tmainmenu is dropped down or not ?...

type

  TForm1 = class(TForm)

    // ...

  private

    IsMenuOpen: Boolean;

    procedure WMMENUSELECT(var message: TWMMENUSELECT); message WM_MENUSELECT;

  end;

 

implementation

 

procedure TForm1.WMMENUSELECT(var message: TWMMENUSELECT);

begin

  inherited;

  IsMenuOpen := not ((message.MenuFlag and $FFFF =  0) and (message.Menu = 0));

end;

 

Delphi - .....................................

 

neoturk: ...Check if a tmainmenu is dropped down or not ?...

type

  TForm1 = class(TForm)

    // ...

  private

    IsMenuOpen: Boolean;

    procedure WMMENUSELECT(var message: TWMMENUSELECT); message WM_MENUSELECT;

  end;

 

implementation

 

procedure TForm1.WMMENUSELECT(var message: TWMMENUSELECT);

begin

  inherited;

  IsMenuOpen := not ((message.MenuFlag and $FFFF =  0) and (message.Menu = 0));

end;

 

Delphi - .....................................

 

neoturk: ...Check if a popup menu is open ?...

{

  Using the WM_MENUSELECT message of the form won’t work to check if

  the popup is open. Simply because the parent of the popup is not the

  form (check the popup method of TPopupMenu). A workaround is to use

  the api call yourself :

}

 

type

  TForm1 = class(TForm)

    {...}

    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;

      Shift: TShiftState; X, Y: Integer);

 

  private

    IsMenuOpen: Boolean;

    procedure WMMENUSELECT(var msg: TWMMENUSELECT); message WM_MENUSELECT;

  end;

 

{...}

implementation

 

{...}

 

procedure TForm1.WMMENUSELECT(var msg: TWMMENUSELECT);

begin

  inherited;

  IsMenuOpen := not ((msg.MenuFlag and $FFFF > 0) and

    (msg.Menu = 0));

end;

 

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

begin

  if Button = mbRight then

    with ClientToScreen(Point(X, Y)) do

      TrackPopupMenuEx(PopupMenu1.Handle, TPM_LEFTALIGN, X, Y,

        Self.Handle, nil);

end;

 

Delphi - .....................................

 

neoturk: ...Check if a popup menu is open ?...

{

  Using the WM_MENUSELECT message of the form won’t work to check if

  the popup is open. Simply because the parent of the popup is not the

  form (check the popup method of TPopupMenu). A workaround is to use

  the api call yourself :

}

 

type

  TForm1 = class(TForm)

    {...}

    procedure FormMouseDown(Sender: TObject; Button: TMouseButton;

      Shift: TShiftState; X, Y: Integer);

 

  private

    IsMenuOpen: Boolean;

    procedure WMMENUSELECT(var msg: TWMMENUSELECT); message WM_MENUSELECT;

  end;

 

{...}

implementation

 

{...}

 

procedure TForm1.WMMENUSELECT(var msg: TWMMENUSELECT);

begin

  inherited;

  IsMenuOpen := not ((msg.MenuFlag and $FFFF > 0) and

    (msg.Menu = 0));

end;

 

procedure TForm1.FormMouseDown(Sender: TObject; Button: TMouseButton;

  Shift: TShiftState; X, Y: Integer);

begin

  if Button = mbRight then

    with ClientToScreen(Point(X, Y)) do

      TrackPopupMenuEx(PopupMenu1.Handle, TPM_LEFTALIGN, X, Y,

        Self.Handle, nil);

end;

 

Delphi - .....................................

 

neoturk: ...Read data from another mdichild form ?...

type

  TMDIChildForm = class(TForm)

    Edit1: TEdit;

  private

    { Private declarations }

    procedure ReadDataFromOtherMDIChildForm;

  end;

 

var

  MDIChildForm: TMDIChildForm;

 

implementation

 

{$R *.DFM}

 

uses

  MainForm;

  // Property FormStyle of this form is fsMDIForm

 

procedure TMDIChildForm.ReadDataFromOtherMDIChildForm;

var

  i: Integer;

  DataFromOtherForm: string;

begin

  // Suppose you have created three different MDIChild forms of the same type,

  // each with the following caption: "aaa", "bbb", "ccc".

  // You are currently on form with caption "aaa" and want to read data

  // contained on form with caption "ccc".

  // You can find here the code, you have to use the "as" clause and

  // properties MDIChildCount and MDIChildren:

 

  // First you have to find where the form "ccc" is in memory;

  for i := 0 to MDIForm.MDIChildCount - 1 do

  begin

    if (Pos('ccc', MDIForm.MDIChildren[i].Caption)  0) then

      Break;

  end;

  // Check to see if the form is the last on MDIChildren array and

  // correct I variable

  if (i = MDIChildCount) then Dec(i);

  // I variable contains the index of the form with caption 'ccc'

 

  if (Pos('ccc', MDIForm.MDIChildren[i].Caption)  0) then

  begin

    // If the form with caption 'ccc' exists then you access data and show it

    // The following line of code is very interesting, look at the "as" clause,

    // if you have different types of MDIChild forms, you simply change

    // the type of form after the "as" clause

    // The data you want is contained on Edit1.Text

    with (MDIForm.MDIChildren[I] as TMDIChildForm).Edit1 do

      DataFromOtherForm := Text;

    ShowMessage(DataFromOtherForm);

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Read data from another mdichild form ?...

type

  TMDIChildForm = class(TForm)

    Edit1: TEdit;

  private

    { Private declarations }

    procedure ReadDataFromOtherMDIChildForm;

  end;

 

var

  MDIChildForm: TMDIChildForm;

 

implementation

 

{$R *.DFM}

 

uses

  MainForm;

  // Property FormStyle of this form is fsMDIForm

 

procedure TMDIChildForm.ReadDataFromOtherMDIChildForm;

var

  i: Integer;

  DataFromOtherForm: string;

begin

  // Suppose you have created three different MDIChild forms of the same type,

  // each with the following caption: "aaa", "bbb", "ccc".

  // You are currently on form with caption "aaa" and want to read data

  // contained on form with caption "ccc".

  // You can find here the code, you have to use the "as" clause and

  // properties MDIChildCount and MDIChildren:

 

  // First you have to find where the form "ccc" is in memory;

  for i := 0 to MDIForm.MDIChildCount - 1 do

  begin

    if (Pos('ccc', MDIForm.MDIChildren[i].Caption)  0) then

      Break;

  end;

  // Check to see if the form is the last on MDIChildren array and

  // correct I variable

  if (i = MDIChildCount) then Dec(i);

  // I variable contains the index of the form with caption 'ccc'

 

  if (Pos('ccc', MDIForm.MDIChildren[i].Caption)  0) then

  begin

    // If the form with caption 'ccc' exists then you access data and show it

    // The following line of code is very interesting, look at the "as" clause,

    // if you have different types of MDIChild forms, you simply change

    // the type of form after the "as" clause

    // The data you want is contained on Edit1.Text

    with (MDIForm.MDIChildren[I] as TMDIChildForm).Edit1 do

      DataFromOtherForm := Text;

    ShowMessage(DataFromOtherForm);

  end;

end;

 

Delphi - .....................................

 

neoturk: ...Check if a control is partially covered by another window ?...

{

 

  You would have to iterate over all windows above yours in Z-order and

  check for each window you find if it has the WS_EX_TOPMOST exstyle set

  and is visible.

  If it has, you have to get its window rectangle (GetWindowRect) and test

  if that overlaps your window.

 

  Example:

 

}

 

procedure TForm1.Button1Click(Sender: TObject);

var

  wnd: HWND;

 

  function IsTopMost(wnd: HWND): Boolean;

  begin

    Result := (GetWindowLong(wnd, GWL_EXSTYLE) and WS_EX_TOPMOST) <> 0;

  end;

 

  procedure logWindowInfo(wnd: HWND);

  const

    visString: array[Boolean] of string = ('not ', '');

  var

    buffer: array[0..256] of Char;

    r:      TRect;

  begin

    if wnd = 0 then Exit;

    GetClassName(wnd, buffer, SizeOf(buffer));

    with Memo1.Lines do

    begin

      Add(Format(' Window of class %s ', [buffer]));

      GetWindowRect(wnd, r);

      Add(Format(' at (%d,%d):(%d,%d)', [r.Left, r.Top, r.Right, r.Bottom]));

      Add(Format(' Window is %svisible', [visString[IsWindowVisible(wnd)]]));

      Add(Format(' Window is %stopmost', [visString[IsTopmost(wnd)]]));

    end;

  end;

 

begin

  Memo1.Clear;

  wnd := Handle;

  repeat

    wnd := GetNextWindow(wnd, GW_HWNDPREV);

    LogWindowInfo(wnd);

  until wnd = 0;

  Memo1.Lines.Add('End log.');

end;

 

Delphi - .....................................

 

neoturk: ...Check if a control is partially covered by another window ?...

{

 

  You would have to iterate over all windows above yours in Z-order and

  check for each window you find if it has the WS_EX_TOPMOST exstyle set

  and is visible.

  If it has, you have to get its window rectangle (GetWindowRect) and test

  if that overlaps your window.

 

  Example:

 

}

 

procedure TForm1.Button1Click(Sender: TObject);

var

  wnd: HWND;

 

  function IsTopMost(wnd: HWND): Boolean;

  begin

    Result := (GetWindowLong(wnd, GWL_EXSTYLE) and WS_EX_TOPMOST) <> 0;

  end;

 

  procedure logWindowInfo(wnd: HWND);

  const

    visString: array[Boolean] of string = ('not ', '');

  var

    buffer: array[0..256] of Char;

    r:      TRect;

  begin

    if wnd = 0 then Exit;

    GetClassName(wnd, buffer, SizeOf(buffer));

    with Memo1.Lines do

    begin

      Add(Format(' Window of class %s ', [buffer]));

      GetWindowRect(wnd, r);

      Add(Format(' at (%d,%d):(%d,%d)', [r.Left, r.Top, r.Right, r.Bottom]));

      Add(Format(' Window is %svisible', [visString[IsWindowVisible(wnd)]]));

      Add(Format(' Window is %stopmost', [visString[IsTopmost(wnd)]]));

    end;

  end;

 

begin

  Memo1.Clear;

  wnd := Handle;

  repeat

    wnd := GetNextWindow(wnd, GW_HWNDPREV);

    LogWindowInfo(wnd);

  until wnd = 0;

  Memo1.Lines.Add('End log.');

end;

 

Delphi - .....................................

 

neoturk: ...Prevent a control from redrawing [refreshing] ?...

{

  Question:

 

  Is there a way to stop a component from refreshing until I've completed some

  processing?

 

  Answer:

 

  Yes. Most controls can be blocked from redrawing by sending a WM_SETREDRAW

  message with wParam = 0 to them. Once you have finished the changes you send

  another WM_SETREDRAW with wparam = 1. For a grid this would look like this:

}

 

{

  Frage:

 

  Gibt es eine Möglichkeit, dass sich eine Komponente solange nicht neu zeichnet,

  bis ich mit einer Verarbeitungsroutine fertig bin?

 

  Antwort:

 

  Ja. Die meisten Controls können "eingefroren" werden, indem man ihnen ein

  WM_SETREDRAW Nachricht mit wParam = 0 schickt.

  Danach kann man WM_SETREDRAW mit wparam = 1 schicken, um das Updaten wieder zulassen.

  Für ein Grid sieht es z.B so aus:

}

 

 

procedure LockControl(c: TWinControl; bLock: Boolean);

begin

  if (c = nil) or (c.Handle = 0) then Exit;

  if bLock then

    SendMessage(c.Handle, WM_SETREDRAW, 0, 0)

  else

  begin

    SendMessage(c.Handle, WM_SETREDRAW, 1, 0);

    RedrawWindow(c.Handle, nil, 0,

      RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  LockControl(DBGrid1, True);

  try

    // do convoluted things to the grid

  finally

    LockControl(DBGrid1, False);

  end;

end;

 

{

  A number of controls have a build-in way to do that, the BeginUpdate and

  EndUpdate methods. You often find these not on the control itself but on

  some object property that manages the controls data, e.g. for a TMemo you use

  Lines.BeginUpdate and Lines.EndUpdate. The EndUpdate automatically forces a

  redraw of the control.

}

 

{

  Viele Controls besitzen schon die Methoden BeginUpdate und EndUpdate.

  Meistens findest man diese Methoden nicht direkt beim Control aber bei

  einer Objekt Eigenschaft, welche diese Methoden aufweist.

  Bei einem TMemo kann man z.B Lines.BeginUpdate und Lines.EndUpdate aufrufen.

  Mit BeginUpdate kann man verhindern, daß die Bildschirmanzeige aktualisiert wird,

  wenn Einträge angehängt, gelöscht und eingefügt werden. EndUpdate veranlasst

  das Control neu zu zeichnen.

}

 

Delphi - .....................................

 

neoturk: ...Prevent a control from redrawing [refreshing] ?...

{

  Question:

 

  Is there a way to stop a component from refreshing until I've completed some

  processing?

 

  Answer:

 

  Yes. Most controls can be blocked from redrawing by sending a WM_SETREDRAW

  message with wParam = 0 to them. Once you have finished the changes you send

  another WM_SETREDRAW with wparam = 1. For a grid this would look like this:

}

 

{

  Frage:

 

  Gibt es eine Möglichkeit, dass sich eine Komponente solange nicht neu zeichnet,

  bis ich mit einer Verarbeitungsroutine fertig bin?

 

  Antwort:

 

  Ja. Die meisten Controls können "eingefroren" werden, indem man ihnen ein

  WM_SETREDRAW Nachricht mit wParam = 0 schickt.

  Danach kann man WM_SETREDRAW mit wparam = 1 schicken, um das Updaten wieder zulassen.

  Für ein Grid sieht es z.B so aus:

}

 

 

procedure LockControl(c: TWinControl; bLock: Boolean);

begin

  if (c = nil) or (c.Handle = 0) then Exit;

  if bLock then

    SendMessage(c.Handle, WM_SETREDRAW, 0, 0)

  else

  begin

    SendMessage(c.Handle, WM_SETREDRAW, 1, 0);

    RedrawWindow(c.Handle, nil, 0,

      RDW_ERASE or RDW_FRAME or RDW_INVALIDATE or RDW_ALLCHILDREN);

  end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

begin

  LockControl(DBGrid1, True);

  try

    // do convoluted things to the grid

  finally

    LockControl(DBGrid1, False);

  end;

end;

 

{

  A number of controls have a build-in way to do that, the BeginUpdate and

  EndUpdate methods. You often find these not on the control itself but on

  some object property that manages the controls data, e.g. for a TMemo you use

  Lines.BeginUpdate and Lines.EndUpdate. The EndUpdate automatically forces a

  redraw of the control.

}

 

{

  Viele Controls besitzen schon die Methoden BeginUpdate und EndUpdate.

  Meistens findest man diese Methoden nicht direkt beim Control aber bei

  einer Objekt Eigenschaft, welche diese Methoden aufweist.

  Bei einem TMemo kann man z.B Lines.BeginUpdate und Lines.EndUpdate aufrufen.

  Mit BeginUpdate kann man verhindern, daß die Bildschirmanzeige aktualisiert wird,

  wenn Einträge angehängt, gelöscht und eingefügt werden. EndUpdate veranlasst

  das Control neu zu zeichnen.

}

 

Delphi - .....................................

Bu web sitesi ücretsiz olarak Bedava-Sitem.com ile oluşturulmuştur. Siz de kendi web sitenizi kurmak ister misiniz?
Ücretsiz kaydol