Programlama yapalım ve Öğrenelim. - Delphi Eğitim162
  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: ...Making the enter key act like tab ?...

{

  This code gives the  key the same habbit as the key to

  change focus between Controls.

 

  Mit diesem Code kann man sich mit der Enter Taste zwischen mehreren

  Textfeldern bewegen.(anstatt nur mit der Tabulatortaste)

}

 

// Form1.KeyPreview := True !

 

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);

begin

  if Key = #13 then

  begin

    Key := #0;

    { check if SHIFT - Key is pressed }

    if GetKeyState(VK_Shift) and $8000 <> 0 then

      PostMessage(Handle, WM_NEXTDLGCTL, 1, 0)

    else

      PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);

  end;

end;

 

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

 

neoturk: ...Making the enter key act like tab ?...

{

  This code gives the  key the same habbit as the key to

  change focus between Controls.

 

  Mit diesem Code kann man sich mit der Enter Taste zwischen mehreren

  Textfeldern bewegen.(anstatt nur mit der Tabulatortaste)

}

 

// Form1.KeyPreview := True !

 

procedure TForm1.FormKeyPress(Sender: TObject; var Key: Char);

begin

  if Key = #13 then

  begin

    Key := #0;

    { check if SHIFT - Key is pressed }

    if GetKeyState(VK_Shift) and $8000 <> 0 then

      PostMessage(Handle, WM_NEXTDLGCTL, 1, 0)

    else

      PostMessage(Handle, WM_NEXTDLGCTL, 0, 0);

  end;

end;

 

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

 

neoturk: ...Reduce a form by right-clicking on the titlebar ?...

type

  TForm1 = class(TForm)

  private

    { Private-Deklarationen }

    FOldHeight: Integer;

    procedure WMNCRButtonDown(var Msg: TWMNCRButtonDown); message WM_NCRBUTTONDOWN;

  public

    { Public-Deklarationen }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

procedure TForm1.WMNCRButtonDown(var Msg: TWMNCRButtonDown);

begin

  if (Msg.HitTest = HTCAPTION) then

    if (ClientHeight = 0) then

    begin

      ClientHeight := FOldHeight;

      Application.ProcessMessages;

    end

    else

    begin

      FOldHeight   := ClientHeight;

      ClientHeight := 0;

      Application.ProcessMessages;

    end

end;

 

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

 

neoturk: ...Reduce a form by right-clicking on the titlebar ?...

type

  TForm1 = class(TForm)

  private

    { Private-Deklarationen }

    FOldHeight: Integer;

    procedure WMNCRButtonDown(var Msg: TWMNCRButtonDown); message WM_NCRBUTTONDOWN;

  public

    { Public-Deklarationen }

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.DFM}

 

procedure TForm1.WMNCRButtonDown(var Msg: TWMNCRButtonDown);

begin

  if (Msg.HitTest = HTCAPTION) then

    if (ClientHeight = 0) then

    begin

      ClientHeight := FOldHeight;

      Application.ProcessMessages;

    end

    else

    begin

      FOldHeight   := ClientHeight;

      ClientHeight := 0;

      Application.ProcessMessages;

    end

end;

 

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

 

neoturk: ...Position an inputquery centered over a form ?...

// I borrowed the code from InputQuery and

// added the stuff to center the InputQuery

// form on top of another form instead of

// positioning it in the middle of the screen.

 

 

// Dieser Code positioniert die Input Box in die

// Mitte der Form und nicht in die Mitte des

// Bildschirms.

 

function GetAveCharSize(Canvas: TCanvas): TPoint;

var

  I: Integer;

  Buffer: array[0..51] of Char;

begin

  for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));

  for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));

  GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));

  Result.X := Result.X div 52;

end;

 

function MyInputQuery(const ACaption, APrompt: string;

  var Value: string): Boolean; overload;

const

  SMsgDlgOK = 'OK';

  SMsgDlgCancel = 'Cancel';

var

  x, y, w, h: Integer;

  Form: TForm;

  Prompt: TLabel;

  Edit: TEdit;

  DialogUnits: TPoint;

  ButtonTop, ButtonWidth, ButtonHeight: Integer;

begin

  Result := False;

  Form   := TForm.Create(Application);

  with Form do

    try

      Canvas.Font  := Font;

      DialogUnits  := GetAveCharSize(Canvas);

      BorderStyle  := bsDialog;

      Caption      := ACaption;

      ClientWidth  := MulDiv(180, DialogUnits.X, 4);

      ClientHeight := MulDiv(63, DialogUnits.Y, 8);

 

      // center Horzontally

      w := (Form1.Width - Form.Width) div 2;

      X := Form1.Left + W;

      if x < 0 then

        x := 0

      else if x + w > Screen.Width then x := Screen.Width - Form.Width;

      Form.Left := X;

 

      // center vertically

      h := (Form1.Height - Form.Height) div 2;

      y := Form1.Top + h;

      if y < 0 then

        y := 0

      else if y + h > Screen.Height then y := Screen.Height - Form.Height;

      Form.Left := X;

      Form.Top  := Y;

 

      Prompt := TLabel.Create(Form);

      with Prompt do

      begin

        Parent   := Form;

        AutoSize := True;

        Left     := MulDiv(8, DialogUnits.X, 4);

        Top      := MulDiv(8, DialogUnits.Y, 8);

        Caption  := APrompt;

      end;

      Edit := TEdit.Create(Form);

      with Edit do

      begin

        Parent    := Form;

        Left      := Prompt.Left;

        Top       := MulDiv(19, DialogUnits.Y, 8);

        Width     := MulDiv(164, DialogUnits.X, 4);

        MaxLength := 255;

        Text      := Value;

        SelectAll;

      end;

      ButtonTop    := MulDiv(41, DialogUnits.Y, 8);

      ButtonWidth  := MulDiv(50, DialogUnits.X, 4);

      ButtonHeight := MulDiv(14, DialogUnits.Y, 8);

      with TButton.Create(Form) do

      begin

        Parent      := Form;

        Caption     := SMsgDlgOK;

        ModalResult := mrOk;

        default     := True;

        SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,

          ButtonHeight);

      end;

      with TButton.Create(Form) do

      begin

        Parent      := Form;

        Caption     := SMsgDlgCancel;

        ModalResult := mrCancel;

        Cancel      := True;

        SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,

          ButtonHeight);

      end;

 

      if ShowModal = mrOk then

      begin

        Value  := Edit.Text;

        Result := True;

      end;

    finally

      Form.Free;

    end;

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

var

  str: string;

begin

  if MyInputQuery('Question', 'Whats your name ?', str) then

    label1.Caption := str;

end;

 

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

 

neoturk: ...Position an inputquery centered over a form ?...

// I borrowed the code from InputQuery and

// added the stuff to center the InputQuery

// form on top of another form instead of

// positioning it in the middle of the screen.

 

 

// Dieser Code positioniert die Input Box in die

// Mitte der Form und nicht in die Mitte des

// Bildschirms.

 

function GetAveCharSize(Canvas: TCanvas): TPoint;

var

  I: Integer;

  Buffer: array[0..51] of Char;

begin

  for I := 0 to 25 do Buffer[I] := Chr(I + Ord('A'));

  for I := 0 to 25 do Buffer[I + 26] := Chr(I + Ord('a'));

  GetTextExtentPoint(Canvas.Handle, Buffer, 52, TSize(Result));

  Result.X := Result.X div 52;

end;

 

function MyInputQuery(const ACaption, APrompt: string;

  var Value: string): Boolean; overload;

const

  SMsgDlgOK = 'OK';

  SMsgDlgCancel = 'Cancel';

var

  x, y, w, h: Integer;

  Form: TForm;

  Prompt: TLabel;

  Edit: TEdit;

  DialogUnits: TPoint;

  ButtonTop, ButtonWidth, ButtonHeight: Integer;

begin

  Result := False;

  Form   := TForm.Create(Application);

  with Form do

    try

      Canvas.Font  := Font;

      DialogUnits  := GetAveCharSize(Canvas);

      BorderStyle  := bsDialog;

      Caption      := ACaption;

      ClientWidth  := MulDiv(180, DialogUnits.X, 4);

      ClientHeight := MulDiv(63, DialogUnits.Y, 8);

 

      // center Horzontally

      w := (Form1.Width - Form.Width) div 2;

      X := Form1.Left + W;

      if x < 0 then

        x := 0

      else if x + w > Screen.Width then x := Screen.Width - Form.Width;

      Form.Left := X;

 

      // center vertically

      h := (Form1.Height - Form.Height) div 2;

      y := Form1.Top + h;

      if y < 0 then

        y := 0

      else if y + h > Screen.Height then y := Screen.Height - Form.Height;

      Form.Left := X;

      Form.Top  := Y;

 

      Prompt := TLabel.Create(Form);

      with Prompt do

      begin

        Parent   := Form;

        AutoSize := True;

        Left     := MulDiv(8, DialogUnits.X, 4);

        Top      := MulDiv(8, DialogUnits.Y, 8);

        Caption  := APrompt;

      end;

      Edit := TEdit.Create(Form);

      with Edit do

      begin

        Parent    := Form;

        Left      := Prompt.Left;

        Top       := MulDiv(19, DialogUnits.Y, 8);

        Width     := MulDiv(164, DialogUnits.X, 4);

        MaxLength := 255;

        Text      := Value;

        SelectAll;

      end;

      ButtonTop    := MulDiv(41, DialogUnits.Y, 8);

      ButtonWidth  := MulDiv(50, DialogUnits.X, 4);

      ButtonHeight := MulDiv(14, DialogUnits.Y, 8);

      with TButton.Create(Form) do

      begin

        Parent      := Form;

        Caption     := SMsgDlgOK;

        ModalResult := mrOk;

        default     := True;

        SetBounds(MulDiv(38, DialogUnits.X, 4), ButtonTop, ButtonWidth,

          ButtonHeight);

      end;

      with TButton.Create(Form) do

      begin

        Parent      := Form;

        Caption     := SMsgDlgCancel;

        ModalResult := mrCancel;

        Cancel      := True;

        SetBounds(MulDiv(92, DialogUnits.X, 4), ButtonTop, ButtonWidth,

          ButtonHeight);

      end;

 

      if ShowModal = mrOk then

      begin

        Value  := Edit.Text;

        Result := True;

      end;

    finally

      Form.Free;

    end;

end;

 

 

procedure TForm1.Button1Click(Sender: TObject);

var

  str: string;

begin

  if MyInputQuery('Question', 'Whats your name ?', str) then

    label1.Caption := str;

end;

 

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

 

neoturk: ...Close a form animated ?...

var

  tutup: Boolean;

  i: Integer;

 

procedure TForm1.Timer1Timer(Sender: TObject);

var

  reg1, reg2: hrgn;

begin

  if tutup = True then

  begin

    i := i + 10;

    reg1 := CreateRoundRectRgn(0 + i, 0 + i, Width - i, Height - i, 20, 20);

    SetWindowRgn(Handle, reg1, True);

  end;

 

  if i >= Width then

  begin

    tutup := False;

    i := 1;

  end;

 

  if tutup = False then

  begin

    i := i + 10;

    reg1 := CreateRectRgn(0, 0, (Width div 2) - i, Height);

    reg2 := CreateRectRgn((Width div 2) + i, 0, Width, Height);

    CombineRgn(reg1, reg1, reg2, rgn_or);

    SetWindowRgn(Handle, reg1, True);

    if i >= Width div 2 then

    begin

      tutup := True;

      i := 1;

    end;

  end;

end;

 

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);

var

  reg1: hrgn;

begin

  i := 1;

  timer1.Enabled := True;

  if MessageDlg('Exit now ?',

    mtConfirmation, [mbYes, mbNo], 0) = mrYes then

    CanClose := True

  else

  begin

    CanClose := False;

    timer1.Enabled := False;

    reg1 := CreateRoundRectRgn(0, 0, Width, Height, 0, 0);

    SetWindowRgn(Handle, reg1, True);

  end;

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  tutup := True;

  timer1.Enabled := False;

 

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

 

neoturk: ...Close a form animated ?...

var

  tutup: Boolean;

  i: Integer;

 

procedure TForm1.Timer1Timer(Sender: TObject);

var

  reg1, reg2: hrgn;

begin

  if tutup = True then

  begin

    i := i + 10;

    reg1 := CreateRoundRectRgn(0 + i, 0 + i, Width - i, Height - i, 20, 20);

    SetWindowRgn(Handle, reg1, True);

  end;

 

  if i >= Width then

  begin

    tutup := False;

    i := 1;

  end;

 

  if tutup = False then

  begin

    i := i + 10;

    reg1 := CreateRectRgn(0, 0, (Width div 2) - i, Height);

    reg2 := CreateRectRgn((Width div 2) + i, 0, Width, Height);

    CombineRgn(reg1, reg1, reg2, rgn_or);

    SetWindowRgn(Handle, reg1, True);

    if i >= Width div 2 then

    begin

      tutup := True;

      i := 1;

    end;

  end;

end;

 

procedure TForm1.FormCloseQuery(Sender: TObject; var CanClose: Boolean);

var

  reg1: hrgn;

begin

  i := 1;

  timer1.Enabled := True;

  if MessageDlg('Exit now ?',

    mtConfirmation, [mbYes, mbNo], 0) = mrYes then

    CanClose := True

  else

  begin

    CanClose := False;

    timer1.Enabled := False;

    reg1 := CreateRoundRectRgn(0, 0, Width, Height, 0, 0);

    SetWindowRgn(Handle, reg1, True);

  end;

end;

 

procedure TForm1.FormCreate(Sender: TObject);

begin

  tutup := True;

  timer1.Enabled := False;

 

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

 

neoturk: ...Change the mainform at runtime ?...

procedure SetAsMainForm(aForm:TForm);

var

  P:Pointer;

begin

  P := @Application.Mainform;

  Pointer(P^) := aForm;

end;

 

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

 

// Example of Usage:

 

{

Question:

 

  If my application is main.exe and the main form is form1, form1 displays

  when it runs. I would like to display other forms based on the parameter

  passed.

  main.exe param1 will display form2 as the first form

  main.exe param2 with display form3 as the first form

 

Answer:

}

 

program Project1;

 

uses

  Forms,

  Unit1 in 'Unit1.pas' {Form1},

  Unit2 in 'Unit2.pas' {Form2},

  Unit3 in 'Unit3.pas' {Form3};

 

{$R *.res}

 

procedure SetAsMainForm(aForm:TForm);

var

  P:Pointer;

begin

  P := @Application.Mainform;

  Pointer(P^) := aForm;

end;

 

begin

  Application.Initialize;

  Application.CreateForm(TForm1, Form1);

  Application.CreateForm(TForm2, Form2);

  Application.CreateForm(TForm3, Form3);

 

  if Paramstr(1) = 'Param1' then

    SetAsMainForm(Form2);

 

  if Paramstr(1) = 'Param2' then

    SetAsMainForm(Form3);

 

  Application.Run;

end.

 

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

 

neoturk: ...Change the mainform at runtime ?...

procedure SetAsMainForm(aForm:TForm);

var

  P:Pointer;

begin

  P := @Application.Mainform;

  Pointer(P^) := aForm;

end;

 

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

 

// Example of Usage:

 

{

Question:

 

  If my application is main.exe and the main form is form1, form1 displays

  when it runs. I would like to display other forms based on the parameter

  passed.

  main.exe param1 will display form2 as the first form

  main.exe param2 with display form3 as the first form

 

Answer:

}

 

program Project1;

 

uses

  Forms,

  Unit1 in 'Unit1.pas' {Form1},

  Unit2 in 'Unit2.pas' {Form2},

  Unit3 in 'Unit3.pas' {Form3};

 

{$R *.res}

 

procedure SetAsMainForm(aForm:TForm);

var

  P:Pointer;

begin

  P := @Application.Mainform;

  Pointer(P^) := aForm;

end;

 

begin

  Application.Initialize;

  Application.CreateForm(TForm1, Form1);

  Application.CreateForm(TForm2, Form2);

  Application.CreateForm(TForm3, Form3);

 

  if Paramstr(1) = 'Param1' then

    SetAsMainForm(Form2);

 

  if Paramstr(1) = 'Param2' then

    SetAsMainForm(Form3);

 

  Application.Run;

end.

 

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

 

neoturk: ...Export a tlistview to a tstringgrid ?...

procedure ListView2StringGrid(Listview: TListView; StringGrid: TStringGrid);

const

  MAX_SUBITEMS = 5;

var

  i, j: Integer;

begin

  with ListView do

    for i := 0 to Items.Count - 1 do

    begin

      {Get Item of First Column}

      StringGrid.Cells[1, i + 1] := Items[i].Caption;

      {loop through SubItems}

      for j := 0 to MAX_SUBITEMS do

      begin

        if Items[i].SubItems.Count > j then

          StringGrid.Cells[j + 2, i + 1] := Items[i].SubItems.Strings[j]

        else

          break;

      end;

    end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  i: Integer;

begin

  // Clear the StringGrid if necessary

  // Falls nötig, zuerst das StringGrid löschen

  i := 0;

  while i < StringGrid1.RowCount do

  begin

    StringGrid1.Rows[i].Clear;

    Inc(i);

  end;

  // Copy ListView1 to StringGrid1

  ListView2StringGrid(ListView1, StringGrid1);

end;

 

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

 

neoturk: ...Export a tlistview to a tstringgrid ?...

procedure ListView2StringGrid(Listview: TListView; StringGrid: TStringGrid);

const

  MAX_SUBITEMS = 5;

var

  i, j: Integer;

begin

  with ListView do

    for i := 0 to Items.Count - 1 do

    begin

      {Get Item of First Column}

      StringGrid.Cells[1, i + 1] := Items[i].Caption;

      {loop through SubItems}

      for j := 0 to MAX_SUBITEMS do

      begin

        if Items[i].SubItems.Count > j then

          StringGrid.Cells[j + 2, i + 1] := Items[i].SubItems.Strings[j]

        else

          break;

      end;

    end;

end;

 

procedure TForm1.Button1Click(Sender: TObject);

var

  i: Integer;

begin

  // Clear the StringGrid if necessary

  // Falls nötig, zuerst das StringGrid löschen

  i := 0;

  while i < StringGrid1.RowCount do

  begin

    StringGrid1.Rows[i].Clear;

    Inc(i);

  end;

  // Copy ListView1 to StringGrid1

  ListView2StringGrid(ListView1, StringGrid1);

end;

 

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

 

neoturk: ...Prevent windows from minimizing a form ?...

The Windows Taskbar function "Minimize all Windows" minimizes all Windows even if they don't have a minimize button.

The following code will prevent a form from minimizing through windows.

 

Die Funktion "Alle Fenster minimieren" aus der Windows Taskbar minimiert alle Fenster, auch solche die eigentlich keine Minimieren-Schaltfläche besitzen. Der folgende Code verhindert das Minimieren eines Fensters.

 

implementation

 

procedure TForm1.WMShowWindow(var Msg: TWMShowWindow);

begin

  if not Msg.Show then

    Msg.Result := 0

  else

    inherited;

end;

 

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

 

neoturk: ...Prevent windows from minimizing a form ?...

The Windows Taskbar function "Minimize all Windows" minimizes all Windows even if they don't have a minimize button.

The following code will prevent a form from minimizing through windows.

 

Die Funktion "Alle Fenster minimieren" aus der Windows Taskbar minimiert alle Fenster, auch solche die eigentlich keine Minimieren-Schaltfläche besitzen. Der folgende Code verhindert das Minimieren eines Fensters.

 

implementation

 

procedure TForm1.WMShowWindow(var Msg: TWMShowWindow);

begin

  if not Msg.Show then

    Msg.Result := 0

  else

    inherited;

end;

 

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

 

neoturk: ...Shape a form to a bitmap ?...

unit Unit1;

 

interface

 

uses

  Windows, Classes, SysUtils, Graphics, Forms;

 

type

  TRGBArray = array[0..32767] of TRGBTriple;

  PRGBArray = ^TRGBArray;

 

type

  TForm1 = class(TForm)

    procedure FormCreate(Sender: TObject);

    procedure FormDestroy(Sender: TObject);

  private

    { Private declarations }

    FRegion: THandle;

    function CreateRegion(Bmp: TBitmap): THandle;

  end;

 

var

  Form1: TForm1;

 

implementation

 

{$R *.dfm}

 

function TForm1.CreateRegion(Bmp: TBitmap): THandle;

var

  X, Y, StartX: Integer;

  Excl: THandle;

  Row: PRGBArray;

  TransparentColor: TRGBTriple;

begin

  Bmp.PixelFormat := pf24Bit;

 

  Result := CreateRectRGN(0, 0, Bmp.Width, Bmp.Height);

 

  for Y := 0 to Bmp.Height - 1 do

  begin

    Row := Bmp.Scanline[Y];

 

    StartX := -1;

 

    if Y = 0 then

      TransparentColor := Row[0];

 

    for X := 0 to Bmp.Width - 1 do

    begin

      if (Row[X].rgbtRed = TransparentColor.rgbtRed) and

        (Row[X].rgbtGreen = TransparentColor.rgbtGreen) and

        (Row[X].rgbtBlue = TransparentColor.rgbtBlue) then

      begin

        if StartX = -1 then StartX := X;

      end

      else

      begin

        if StartX > -1 then

        begin

          Excl := CreateRectRGN(StartX, Y, X + 1, Y + 1);

          try

            CombineRGN(Result, Result, Excl, RGN_DIFF);

            StartX := -1;

          finally

            DeleteObject(Excl);

          end;

        end;

      end;

    end;

 

    if StartX > -1 then

    begin

      Excl := CreateRectRGN(StartX, Y, Bmp.Width, Y + 1);

      try

        CombineRGN(Result, Result, Excl, RGN_DIFF);

      finally

        DeleteObject(Excl);

      end;

    end;

  end;

end;

 

procedure TForm1.FormCreate(Sender: TObject);

var

  Bmp: TBitmap;

begin

  Bmp := TBitmap.Create;

  try

    Bmp.LoadFromFile('C:YourBitmap.bmp');

    FRegion := CreateRegion(Bmp);

    SetWindowRGN(Handle, FRegion, True);

  finally

    Bmp.Free;

  end;

end;

 

procedure TForm1.FormDestroy(Sender: TObject);

begin

  DeleteObject(FRegion);

end;

 

end.

 

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