2011-11-27 11 views
1

나는 Delphi7, MS VistaDevart's dbExpress 드라이버 (버전 4.70)를 사용하고 있습니다. 나는 TSQLConnection, TSQLTable (tabA), TDataSetProvider, TClientDataSet (cdsA), DataSourceDBGrid을 떨어 뜨린다.Delphi TClientDataSet 문제 찾기

그래픽 디자인 도구를 통해 모든 설정을했습니다. 모든 것은 잘 작동하는데, cdsA을 열면 Grid의 모든 데이터를 볼 수 있습니다.

procedure TForm1.Button1Click(Sender: TObject); 
var 
    fields, values: string; 
begin 
    cdsA.Close; 
    cdsA.Open; 
    fields := 'fielda;fieldb'; 
    values := Edit1.Text+';'+Edit2.Text; 
    cdsA.SetKey; 
    cdsA.Locate(fields, values, [loCaseInsensitive]); 
end; 

fieldAfieldB이 테이블에 존재 너무 cdsA.Fields에 정의되어 있습니다 : 여기 내 코드입니다. 이 코드를 실행하면 Locate 명령어가 예외 EVariantInvalidArgError ... Invalid argument을 생성합니다. 나는 무엇이 잘못되었는지 궁금합니다. TIA.

Francesco

답변

5

코드가 잘못되었습니다. :)

procedure TForm1.Button1Click(Sender: TObject); 
var 
    fields, values: string; 
begin 
    // Closing the CDS and opening it every time is foolish. Just 
    // open it if it's not already open. 
    if not cdsA.Active then 
    cdsA.Open; 

    // List of column names. Since column (field) names are always 
    // strings, can just use semicolon-separated values 
    fields := 'fielda;fieldb'; 

    // Values for columns. Since these could be any type, you can't 
    // simply use semicolon-separated strings. You have to pass an 
    // array of Variants. The easiest way is to just create it and 
    // populate it, and let reference counting release it when it's 
    // out of scope 
    values := VarArrayOf([Edit1.Text, Edit2.Text]); 

    // No call to SetKey here. SetKey is used with FindKey, not Locate 
    cdsA.Locate(fields, values, [loCaseInsensitive]); 
end; 
+0

네 말이 맞아. 고맙습니다. – Francesco