DELPHI ipuçları ve ayrıntıları

Son güncelleme: 03.03.2006 20:57
  • TTABLE/TQUERY ÜZERİNDE ARTTIRARAK ARAMA

    TEdit kullanarak, TTable üzerinde arttırmalı arama yapmak için, Tedid bileşeninin OnChange olay yordamına, aşağıdaki kod yazılır.

    procedure TForm1.Edit1Cha nge(Sender: TObject);
    begin
    With Edit1 do
    if Text <> '' then
    Table1.FindNear est([Text]);
    end;
    // Bu türlü bir arama Tquerry üzerinde yapılacaksa,
    procedure TForm1.Edit1Cha nge(Sender: TObject);
    begin
    With Edit1 do
    if Text <> '' then begin
    Query1.Filter := 'code = '''+Edit1.Text+ '''';
    Query1.FindFirs t;
    end;
    end;
    veya
    procedure TForm1.Edit1Cha nge(Sender: TObject);
    begin
    With Edit1 do
    if Text <> '' then
    Query1.Locate(' code',Edit1.Tex t,[loPartialKey]);
    end;
    // Paradox-Tablo yaratılması
    // Kod içerisinden bir Paradox tablosu şu şekilde yaratılır.
    with TTable.create(s elf) do begin
    DatabaseName := 'C:\temp';
    TableName := 'FOO';
    TableType := ttParadox;
    with FieldDefs do Begin
    Add('Age', ftInteger, 0, True);
    Add('Name', ftString, 25, False);
    Add('Weight', ftFloat, 0, False);
    End;
    IndexDefs.Add(' MainIndex','Int Field', [ixPrimary,
    ixUnique]);
    CreateTable;
    End;
    DBMemo içeriğinin başka bir DBMemo bileşenine aktarılması
    DBMemo6.Lines:= DBMemo5.Lines.A ssign;
    TDBNavigator bileşenin, kod içerisinden kontrol edilmesi
    procedure TForm1.DBNaviga tor1Click(Sende r: TObject; Button:
    TNavigateBtn);
    var
    BtnName: string;
    begin
    case Button of
    nbFirst : BtnName := 'nbFirst';
    nbPrior : BtnName := 'nbPrior';
    nbNext : BtnName := 'nbNext';
    nbLast : BtnName := 'nbLast';
    nbInsert : BtnName := 'nbInsert';
    nbDelete : BtnName := 'nbDelete';
    nbEdit : BtnName := 'nbEdit';
    nbPost : BtnName := 'nbPost';
    nbCancel : BtnName := 'nbCancel';
    nbRefresh: BtnName := 'nbRefresh';
    end;
    MessageDlg(BtnN ame + ' button clicked.', mtInformation,
    [mbOK], 0);
    end;
    -----------------------------------------------------------------
    DBMEMO İÇERİSİNDE BİR METNİN ARANMASI
    procedure Tform1.FindDial og1Find(Sender: TObject);
    var Buff, P, FT : PChar;
    BuffLen : Word;
    begin
    With Sender as TFindDialog do
    begin
    GetMem(FT, Length(FindText ) + 1);
    StrPCopy(FT, FindText);
    BuffLen:= DBMemo1.GetText Len + 1;
    GetMem(Buff,Buf fLen);
    DBMemo1.GetText Buf(Buff,BuffLe n);
    P:= Buff + DBMemo1.SelStar t + DBMemo1.SelLeng th;
    P:= StrPos(P, FT);
    if P = NIL then MessageBeep(0)
    else
    begin
    DBMemo1.SelStar t:= P - Buff;
    DBMemo1.SelLeng th:= Length(FindText );
    end;
    FreeMem(FT, Length(FindText ) + 1);
    FreeMem(Buff,Bu ffLen);
    DBMemo1.SetFocu s;
    end;
    end;
    Şekil 1 : Form1
    kod örneği 1 : form1.dfm
    object Form1: TForm1
    Left = 200
    Top = 108
    Width = 696
    Height = 445
    Caption = 'Form1'
    Font.Charset = DEFAULT_CHARSET
    Font.Color = clWindowText
    Font.Height = -11
    Font.Name = 'MS Sans Serif'
    Font.Style = []
    PixelsPerInch = 96
    TextHeight = 13
    object DBMemo1: TDBMemo
    Left = 16
    Top = 152
    Width = 657
    Height = 193
    DataField = 'Notes'
    DataSource = DataSource1
    TabOrder = 0
    OnDblClick = DBMemo1DblClick
    end
    object DBGrid1: TDBGrid
    Left = 16
    Top = 16
    Width = 657
    Height = 120
    DataSource = DataSource1
    TabOrder = 1
    TitleFont.Chars et = DEFAULT_CHARSET
    TitleFont.Color = clWindowText
    TitleFont.Heigh t = -11
    TitleFont.Name = 'MS Sans Serif'
    TitleFont.Style = []
    end
    object DBNavigator1: TDBNavigator
    Left = 432
    Top = 352
    Width = 240
    Height = 25
    TabOrder = 2
    end
    object DataSource1: TDataSource
    DataSet = Table1
    Left = 138
    Top = 364
    end
    object Table1: TTable
    Active = True
    DatabaseName = 'dbdemos'
    TableName = 'BIOLIFE.DB'
    Left = 220
    Top = 366
    end
    object FindDialog1: TFindDialog
    OnFind = FindDialog1Find
    Left = 40
    Top = 360
    end
    end
    kod örneği 2 : unit1.pas
    unit Unit1;
    interface
    uses
    Windows, Messages, SysUtils, Classes, Graphics, Controls,
    Forms, Dialogs,StdCtrl s, Grids, DBGrids, Db, DBTables,
    DBCtrls, ExtCtrls;
    type
    TForm1 = class(TForm)
    DBMemo1: TDBMemo;
    DataSource1: TDataSource;
    Table1: TTable;
    DBGrid1: TDBGrid;
    FindDialog1: TFindDialog;
    DBNavigator1: TDBNavigator;
    procedure FindDialog1Find (Sender: TObject);
    procedure DBMemo1DblClick (Sender: TObject);
    private
    { Private declarations }
    public
    { Public declarations }
    end;
    var
    Form1: TForm1;
    implementation
    {$R *.DFM}
    procedure Tform1.FindDial og1Find(Sender: TObject);
    var Buff, P, FT : PChar;
    BuffLen : Word;
    begin
    With Sender as TFindDialog do
    begin
    GetMem(FT, Length(FindText ) + 1);
    StrPCopy(FT, FindText);
    BuffLen:= DBMemo1.GetText Len + 1;
    GetMem(Buff,Buf fLen);
    DBMemo1.GetText Buf(Buff,BuffLe n);
    P:= Buff + DBMemo1.SelStar t + DBMemo1.SelLeng th;
    P:= StrPos(P, FT);
    if P = NIL then MessageBeep(0)
    else
    begin
    DBMemo1.SelStar t:= P - Buff;
    DBMemo1.SelLeng th:= Length(FindText );
    end;
    FreeMem(FT, Length(FindText ) + 1);
    FreeMem(Buff,Bu ffLen);
    DBMemo1.SetFocu s;
    end;
    end;
    procedure TForm1.DBMemo1D blClick(Sender: TObject);
    begin
    finddialog1.exe cute;
    end;
    end
#03.03.2006 20:57 0 0 0