كيف التحكم في عناصر جملة SQL؟
#3
(04-03-2020, 12:38 PM)ghostdz كتب : وعليكم السلام ورحمة الله وبركاته
إليك الكود التالي قم بتجريبه 
ملاحظة : عليك إعطاء كل checkbox.tag قيمة حسب الجدول aFieldName

 
كود :
unit Unit2; interface uses   Winapi.Windows, Winapi.Messages, System.SysUtils, System.Variants, System.Classes, Vcl.Graphics,   Vcl.Controls, Vcl.Forms, Vcl.Dialogs, Data.DB, Vcl.StdCtrls, Vcl.Grids,   Vcl.DBGrids, Vcl.ExtCtrls, Data.Win.ADODB, Vcl.Mask, Vcl.DBCtrls; type   TForm2 = class(TForm)     Query: TADOQuery;     NameCheckBox: TCheckBox;     BirthDayCheckBox: TCheckBox;     MarkCheckBox: TCheckBox;     procedure NameCheckBoxClick(Sender: TObject);   private     { Déclarations privées }   public     { Déclarations publiques }     aOrder: array of string;     function GenerateSQL: string;     procedure AddFieldToOrder(FieldName: string);     procedure RemoveFieldFromOrder(FieldName: string);   end; var   Form2: TForm2; implementation {$R *.dfm} procedure TForm2.NameCheckBoxClick(Sender: TObject); const    aFieldName: array[1..3] of string = ('Name', 'BirthDay', 'Mark'); var   Order: string; begin   Query.Active:= False;   if TCheckBox(Sender).Checked then     AddFieldToOrder(aFieldName[TCheckBox(Sender).Tag])   else RemoveFieldFromOrder(aFieldName[TCheckBox(Sender).Tag]);   Query.SQL.Text:= GenerateSQL;   Query.Active:= True; end; function TForm2.GenerateSQL: string; var   Order: string;   I: Integer; begin   Result:= 'SELECT * FROM Table ';   if Length(aOrder) > 0 then   begin     Result:= Result + 'ORDER BY ' + aOrder[0];     for I:= 1 to High(aOrder) do        Result:= Result + ', ' + aOrder[I];   end; end; procedure TForm2.AddFieldToOrder(FieldName: string); var   I: Integer; begin   I:= 0;   begin     while (I <= High(aOrder)) and (UpperCase(aOrder[I]) <> UpperCase(FieldName)) do       I:= I + 1;   end;   if I >= Length(aOrder) then   begin     SetLength(aOrder, I + 1);     aOrder[I]:= FieldName;   end; end; procedure TForm2.RemoveFieldFromOrder(FieldName: string); var   I: Integer; begin   I:= 0;   while (I <= High(aOrder)) and (UpperCase(aOrder[I]) <> UpperCase(FieldName)) do     I:= I + 1;   if I <= High(aOrder) then     Delete(aOrder, I, 1); end; end.

جزاك الله خير ولكن عمل معي في الترتيب بالإسم فقط ولم يعمل مع تاريخ الميلاد و العلامه لا أدري أين الخلل
وهل ممكن معرفة الترتيب على أي checkbox أولا ؟هل يمكن إضافة Label على الفورم بجانب كل checkbox ليبين ترتيبه ،هل تم الترتيب به في المرتبة الأولى أو المرتبة الثانية أو الثالثة؟

هل لك قناة تعليمية أخي الكريم؟
الرد


الردود في هذا الموضوع
كيف التحكم في عناصر جملة SQL؟ - بواسطة ALG2009 - 03-03-2020, 09:34 PM
RE: كيف التحكم في عناصر جملة SQL؟ - بواسطة ALG2009 - 04-03-2020, 09:36 PM

التنقل السريع :


يقوم بقرائة الموضوع: بالاضافة الى ( 1 ) ضيف كريم