菜
菜妹妹
Unregistered / Unconfirmed
GUEST, unregistred user!
我是想把数据库中指定字段的值先读到stringlist再对应在checklistbox中显示,
再根据用户的checked把对应项转换成二进制字符串,然后存到数据库中,编译没错误,
可一运行就保存。再不能解决,我就快疯了呀,救人呀!
procedure TForm1.BitBtn1Click(Sender: TObject);
var stringlist:tstringlist;
n,m,i,j:integer;
kitty:array [0..7] of char;
stre:string;
load:array [0..256] of int64;
begin
n:=0;
m:=0;
checklistbox1:=tchecklistbox.Create(self);
stringlist:=tstringlist.Create();
with ADOTable1 do
stringlist.add(fieldbyname('type').asstring);
i:=stringlist.Count;
for j:=0 to i do
checklistbox1.Items[j]:=stringlist.Strings[j];
checklistbox1.Visible:=true;
if checklistbox1.Checked[m] then
kitty[m]:='1'
else
kitty[m]:='0';
stre:=kitty;
load[n]:=yfDigitToInt(stre,2);
stre:='';
with ADOTable1 do
fields[2].AsInteger :=load[n];
stringlist.Free;
checklistbox1.Free;
end;
function yfDigitToInt(mDigit: string;
mScale: Byte): Int64;
var I: Byte;
L: Integer;
begin
Result := 0;
mDigit := UpperCase(mDigit);
L := Length(mDigit);
for I := 1 to L do
Result := Result + (Pos(mDigit[L - I + 1], ycScaleChar) - 1) * yfIntPower(mScale, I - 1);
end;
//DigitToInt
function yfIntPower(Base: Integer;
Exponent: Integer): Int64;
var I: Integer;
begin
Result := 1;
for I := 1 to Exponent do
Result := Result * Base ;
end;
end.
为什么总是在运行时出错,帮忙呀!
再根据用户的checked把对应项转换成二进制字符串,然后存到数据库中,编译没错误,
可一运行就保存。再不能解决,我就快疯了呀,救人呀!
procedure TForm1.BitBtn1Click(Sender: TObject);
var stringlist:tstringlist;
n,m,i,j:integer;
kitty:array [0..7] of char;
stre:string;
load:array [0..256] of int64;
begin
n:=0;
m:=0;
checklistbox1:=tchecklistbox.Create(self);
stringlist:=tstringlist.Create();
with ADOTable1 do
stringlist.add(fieldbyname('type').asstring);
i:=stringlist.Count;
for j:=0 to i do
checklistbox1.Items[j]:=stringlist.Strings[j];
checklistbox1.Visible:=true;
if checklistbox1.Checked[m] then
kitty[m]:='1'
else
kitty[m]:='0';
stre:=kitty;
load[n]:=yfDigitToInt(stre,2);
stre:='';
with ADOTable1 do
fields[2].AsInteger :=load[n];
stringlist.Free;
checklistbox1.Free;
end;
function yfDigitToInt(mDigit: string;
mScale: Byte): Int64;
var I: Byte;
L: Integer;
begin
Result := 0;
mDigit := UpperCase(mDigit);
L := Length(mDigit);
for I := 1 to L do
Result := Result + (Pos(mDigit[L - I + 1], ycScaleChar) - 1) * yfIntPower(mScale, I - 1);
end;
//DigitToInt
function yfIntPower(Base: Integer;
Exponent: Integer): Int64;
var I: Integer;
begin
Result := 1;
for I := 1 to Exponent do
Result := Result * Base ;
end;
end.
为什么总是在运行时出错,帮忙呀!