开发平台一: B/S和C/S技术结合的一个平台,传输采用的是http协议,终端采用C/S方式。
这种 太多了
procedure TWebModule1.WebModule1WebActionItem7Action(Sender: TObject;
Request: TWebRequest; Response: TWebResponse; var Handled: Boolean);
var
strsql: string;
i: integer;
ms: TMemoryStream;
begin
inc(AccessCount);
strsql := DeStr(Request.QueryFields.Values['sql']);
try
ADODataSet1.CommandText := strsql;
ADODataSet1.Open;
ms := TMemoryStream.Create;
ADOToStream(ADODataSet1, ms, i);
ADODataSet1.Close;
ms.Position := 0;
Response.ContentStream := ms;
inc(TranDataByteCount, ms.Size);
except
on E: Exception do recordEvent('/DataWithSql ' + strsql + ' ' + E.Message);
end;
//
end;
////////
function ADOToStream(DT: TCustomADODataSet; S: tstream; var ECount: integer): boolean;
var
intV, i, k, l, fc, rc: integer;
FT: TFieldType;
str, strV: string;
B: Byte;
FTList: array of TFieldType;
V: OleVariant;
DateTimeV: TDateTime;
FloatV: Extended;
booleanV: boolean;
begin
Result := false;
ECount := 0;
if not dt.Active then
exit;
try
fc := dt.FieldCount;
s.WriteBuffer(fc, 4);
setlength(FTList, fc);
for i := 0 to dt.FieldCount - 1 do
begin
str := dt.Fields.FieldName;
l := length(str);
s.WriteBuffer(l, 4);
s.Write(str[1], l);
ft := dt.Fields.DataType;
s.Write(ft, SIZEOF(ft));
FTList := ft;
l := dt.Fields.Size;
s.WriteBuffer(l, 4);
end;
with dt.Recordset do
begin
rc := RecordCount;
s.WriteBuffer(rc, 4);
if not dt.IsEmpty then
begin
MoveFirst;
for i := 0 to rc - 1 do
begin
for k := 0 to fc - 1 do
begin
v := dt.Recordset.Fields[k].Value;
if VarIsNull(V) then
b := 1
else
b := 0;
s.WriteBuffer(b, 1);
if b = 1 then
Continue;
case FTList[k] of
ftString, ftMemo, ftFixedChar, ftWideString:
begin
strV := v;
l := length(strV);
s.WriteBuffer(l, 4);
s.Write(strV[1], l);
end;
ftDate, ftTime, ftDateTime:
begin
DateTimeV := v;
s.Write(DateTimeV, 8);
end;
ftSmallint, ftInteger, ftWord:
begin
intV := v;
s.Write(intV, 4);
end;
ftFloat, ftCurrency, ftBCD:
begin
FloatV := v;
s.Write(FloatV, 10);
end;
ftBoolean:
begin
booleanV := v;
s.Write(FloatV, 1);
end;
else
;
end;
end;
Inc(ECount);
MoveNext;
end;
end;
end;
Result := true;
except;
end;
setlength(FTList, 0);
end;
function StreamToADO(DT: TADODataSet; S: tstream; var ECount: integer): boolean;
var
intV, i, k, l, fc, rc: integer;
FT: TFieldType;
str, strV: string;
B: Byte;
FTList: array of TFieldType;
V: OleVariant;
DateTimeV: TDateTime;
FloatV: Extended;
booleanV: boolean;
begin
Result := false;
ECount := 0;
try
dt.Close;
dt.DisableControls;
dt.FieldDefs.Clear;
s.ReadBuffer(fc, 4);
setlength(ftList, fc);
for i := 0 to fc - 1 do
begin
s.ReadBuffer(l, 4);
setlength(str, l);
s.ReadBuffer(str[1], l);
s.ReadBuffer(ft, SIZEOF(ft));
FTList := ft;
s.ReadBuffer(l, 4);
DT.FieldDefs.Add(str, ft, l);
end;
dt.CreateDataSet;
dt.Open;
s.ReadBuffer(rc, 4);
with dt do
for i := 1 to rc do
begin
Append;
for k := 0 to fc - 1 do
begin
s.ReadBuffer(b, 1);
if b = 1 then
begin
Fields[k].Value := null;
Continue;
end;
case FTList[k] of
ftString, ftMemo, ftFixedChar, ftWideString:
begin
s.ReadBuffer(l, 4);
setlength(strV, l);
s.ReadBuffer(strV[1], l);
Fields[k].Value := strV;
end;
ftDate, ftTime, ftDateTime:
begin
s.ReadBuffer(DateTimeV, 8);
Fields[k].Value := DateTimeV;
end;
ftSmallint, ftInteger, ftWord:
begin
s.ReadBuffer(intV, 4);
Fields[k].Value := intv;
end;
ftFloat, ftCurrency, ftBCD:
begin
s.ReadBuffer(FloatV, 10);
Fields[k].Value := FloatV;
end;
ftBoolean:
begin
s.ReadBuffer(FloatV, 1);
Fields[k].Value := booleanV;
end;
else
;
end;
end;
Inc(ECount);
end;
Result := true;
except;
end;
try
dt.First;
dt.EnableControls
except;
end;
setlength(FTList, 0);
end;