هل من طريقة ابسط لملأ حقل في جدول من جدول آخر بعد مقارنتهما
#2
السلام عليكم

جولة 1:
جعل التعليمات أكثر مقروئية:

PHP كود :
procedure TForm1.BitBtn1Click(Sender: TObject);
var
  
s1,s2,s3,s4,s5,s6,s7,s8,s9,s10:string;
  
cde, LB: string;
  
Fld: TField;
begin
   s1
:='';s2:='';s3:='';s4:='';s5:='';s6:='';s7:='';s8:='';s9:='';s10:='';

  
with DataModule3 do
  
begin
    abstable2
.First;
    while 
not abstable2.Eof do begin
      
//abstable2.edit;
      
cde := abstable2.FieldByName('cde').asstring;
      
LB := abstable2.fieldbyname('LB').asstring;

      if 
cde = '01' then s1 := LB;
      if 
cde = '02' then s2 := LB;
      if 
cde = '03' then s3 := LB;
      if 
cde = '04' then s4 := LB;
      if 
cde = '05' then s5 := LB;
      if 
cde = '06' then s6 := LB;
      if 
cde = '07' then s7 := LB;
      if 
cde = '08' then s8 := LB;
      if 
cde = '09' then s9 := LB;
      if 
cde = '10' then s10 := LB;
      
//abstable2.Post;
      //abstable2.Next;
    
end;

    
Fld := abstable1.fieldbyname('libelle');
    
abstable1.First;
    while 
not abstable1.Eof do begin
      abstable1
.edit;

      
cde := abstable2.FieldByName('cde').asstring;

      if 
cde = '01' then Fld.asstring := s1;
      if 
cde = '02' then Fld.asstring := s2;
      if 
cde = '03' then Fld.asstring := s3;
      if 
cde = '04' then Fld.asstring := s4;
      if 
cde = '05' then Fld.asstring := s5;
      if 
cde = '06' then Fld.asstring := s6;
      if 
cde = '07' then Fld.asstring := s7;
      if 
cde = '08' then Fld.asstring := s8;
      if 
cde = '09' then Fld.asstring := s9;
      if 
cde = '10' then Fld.asstring := s10;
      
abstable1.Post;
      
abstable1.Next;
    
end;
  
end; // with
end; 
جولة 2:
ايجاد طرق أفضل
مثلا فكرت بأن أستبدل المتغيرات العشر بمصفوفة من 10 عناصر،
(مع افتراض أن الحقول بها قيم ذات دلالة رقمية):


PHP كود :
procedure TForm1.bt1Click(Sender: TObject);
var
  
cde, LB: string;
  
Fld: TField;
  
s: array [1..10] of string;
  
i: integer;
begin
  with DataModule3 
do
  
begin
    abstable2
.First;
    while 
not abstable2.Eof do begin
      cde 
:= abstable2.FieldByName('cde').asstring;
      
LB := abstable2.fieldbyname('LB').asstring;
      for 
i := 1 to 10 do
        if 
StrToInt(cde) = i then
          s
[i] := LB;
    
end;

    
Fld := abstable1.fieldbyname('libelle');
    
abstable1.First;
    while 
not abstable1.Eof do begin
      abstable1
.edit;
      
cde := abstable2.FieldByName('cde').asstring;
      
i := StrToInt(cde);
      
Fld.asstring := s[i];
      
abstable1.Post;
      
abstable1.Next;
    
end;
  
end; // with
end; 
الرد


الردود في هذا الموضوع
هل من طريقة ابسط لملأ حقل في جدول من جدول آخر بعد مقارنتهما - بواسطة shagrouni - 28-06-2010, 11:03 PM

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


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