如何將以下的程式改為com元件呢? |
尚未結案
|
nickcgh6
一般會員 發表:37 回覆:11 積分:9 註冊:2004-07-23 發送簡訊給我 |
以下是小弟的程式碼:
procedure TForm1.Button1Click(Sender: TObject);
var i,j,l:Integer;
begin
if Trim(Edit1.Text) = '' then
begin
ShowMessage('請先輸入條件值');
Edit1.SetFocus;
end
else
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select 基金代號,購買日期,價格,數量,交易動作 From 交易資料表 Where ');
ADOQuery1.SQL.Add('客戶編號 = ''' Edit1.Text '''');
ADOQuery1.Open;
if ADOQuery1.RecordCount=0 then
ShowMessage('無符合條件的內容請重新輸入')
else
begin
i:=1;
With adoquery1 Do
begin
If Not IsEmpty Then
Begin
stringgrid1.ColCount := FieldCount;
stringgrid1.RowCount := RecordCount i;
stringgrid1.FixedCols := 0;
stringgrid1.FixedRows := i;
For j := 0 To FieldCount-1 Do
stringgrid1.Cells[j,0] := Fields[j].FieldName;
l := 0;
While Not Eof Do
Begin For j := 0 To FieldCount-1 Do
stringgrid1.Cells[j,l stringgrid1.FixedRows] :=Fields[j].AsString;
Next;
Inc(l); End;
End; end; 本人想要將其程式改為用ap端來呼叫com做資料的查詢
也就是在ap端我在edit中輸入查詢條件,透過com做處理在顯示在ap這
請問我該傳的參數為幾個,而這幾個參數是控制什麼的
請熱心人士幫幫我,我試了好幾次,參數都傳錯
|
nickcgh6
一般會員 發表:37 回覆:11 積分:9 註冊:2004-07-23 發送簡訊給我 |
這是我依我的想法下去做的
clint端:
procedure TForm1.Button1Click(Sender: TObject);
var id ,i,j,k,m,Col,Lin:integer;
var v,x,y:variant;
begin
m:=1;
v:=vararraycreate([0,9],varvariant);
id:=StrToInt(edit1.Text);
SocketConnection1.Connected:=true;
SocketConnection1.AppServer.mtehod1(id,i,j,v,x,y);
stringgrid1.ColCount:=i;
stringgrid1.RowCount := j;
stringgrid1.FixedCols := 0;
stringgrid1.FixedRows := m;
if x=true then
For Col := 0 To i-1 Do
stringgrid1.Cells[Col,0] := v[col];
Lin := 0;
if y=true then
For Col := 0 To i-1 Do
stringgrid1.Cells[Col,Lin stringgrid1.FixedRows] :=v[Col];
Next;
Inc(Lin);
end;
end. com端:
procedure Tselect.Method1(const a: WideString; var b, c, dataarray, d,
e: OleVariant);
var j,k,l,i:Integer;
begin
if Trim(a) = '' then
begin
ShowMessage('請先輸入條件值');
//Edit1.SetFocus;
end
else
begin
ADOQuery1.Close;
ADOQuery1.SQL.Clear;
ADOQuery1.SQL.Add('Select 基金代號,購買日期,價格,數量,交易動作 From 交易資料表 Where ');
ADOQuery1.SQL.Add('客戶編號 = ''' a '''');
ADOQuery1.Open;
if ADOQuery1.RecordCount=0 then
ShowMessage('無符合條件的內容請重新輸入')
else
begin
i:=1;
// d:=ADOQuery1.FieldCount;
With adoquery1 Do begin
If Not IsEmpty Then
Begin
d:=true;
b:= FieldCount;
c := RecordCount i;
// stringgrid1.FixedCols := 0;
//stringgrid1.FixedRows := i;
For j := 0 To FieldCount-1 Do
dataarray[j,0] := Fields[j].FieldName;
l:= 0;
While Not Eof Do
Begin
e:=true;
For j := 0 To FieldCount-1 Do
dataarray[j] :=Fields[j].AsString;
Next;
Inc(l); End;
end;
end;
end;
end; 我在clint端給它(id,i,j,v,x,y)
id是edit的值
i.j是記錄ADOQuery的filecont跟recordcont
v是記錄資料的陣列
x.y若是=true迴圈就把資料寫到stringgrid
這樣子有錯,請問各位大哥,我該做什麼修改謝謝
|
shunaaron
高階會員 發表:13 回覆:94 積分:106 註冊:2006-10-06 發送簡訊給我 |
在COM那~小弟個人寫法為下
procedure TColckSys.BaseSelect(const BaNa: WideString; BaCo: OleVariant; out BaAy, BaAc: OleVariant); Var SQL:String; i,j:Integer; begin SQL:=''; ADODataSet1.Close; SQL:='Select * From ' BaNa; ADODataSet1.CommandText:=SQL; ADODataSet1.Open; BaCo:=ADODataSet1.FieldCount; BaAc:=ADODataSet1.RecordCount; BaAy:=VarArrayCreate([0,BaCo,0,BaAc],VarVariant); If BaAc > 0 Then Begin For i:= 0 To ADODataSet1.RecordCount-1 Do Begin For j:= 0 To BaCo Do BaAy[j,i]:=VarToStr(ADODataSet1.FieldList.Fields[j].Value); ADODataSet1.Next; End; End; ADODataSet1.Close; end; 以上比較不同的是~ 如果ADODataSet1.RecordCount是大於0表示有資料~ 為何還要用True或False來判斷~只要判斷傳出去的值是否為0即可 在來可以用BaAy:=VarArrayCreate([0,BaCo,0,BaAc],VarVariant)方式來建一個陣列 這樣不用在額外多一個字串陣列出來 在clinet只要宣告tt:Variant;就可以了 在判斷傳出來的值為何 Var inStr:String; Ct,Ay,Ac:Variant; sc.AppServer.BaseSelect(Instr,Ct,Ay,Ac) If Ac > 0 Then .... Else ..
------
程式沒有這麼難 只是還沒打通其中要絕 |
本站聲明 |
1. 本論壇為無營利行為之開放平台,所有文章都是由網友自行張貼,如牽涉到法律糾紛一切與本站無關。 2. 假如網友發表之內容涉及侵權,而損及您的利益,請立即通知版主刪除。 3. 請勿批評中華民國元首及政府或批評各政黨,是藍是綠本站無權干涉,但這裡不是政治性論壇! |