我已經做了這段代碼,而試圖拆分一個字符串分成2個部分,我將保存到數據庫後。現在我已經成功地將3個單詞字符串像「單詞字符編號」一樣分成3個字段,但是當我試圖將只有1個單詞的字符串和像「單詞編號」一樣的字符串分成2個字段時,我得到了我無法理解的錯誤消息。嘗試拆分字符串沒有成功
procedure Split
(const Delimiter: Char;
Input: string;
const Strings: TStrings) ;
begin
Assert(Assigned(Strings)) ;
Strings.Clear;
Strings.Delimiter := Delimiter;
Strings.DelimitedText := Input;
end;
procedure TForm2.Button64Click(Sender: TObject);
var
A: TStringList; i,c:integer;
begin
c:=0;
//for i:= 0 to ListBox1.Items.Count do
//begin
A := TStringList.Create;
// try
// Split(' ',listbox1.Items.Strings[0], A) ;
Split(' ',ListBox1.Items.Strings[ListBox1.ItemIndex], A) ;
// finally
// A.Free;
for i := 48 to 57 do
if A[1]<>char(i) then
c:=1
else
if A[1]=char(i) then
c:=2;
if c=1 then
begin
edit81.Text:=(A[0]+' '+A[1]);
edit82.Text:=A[2];
end
else
if c=2 then
begin
edit81.Text:=A[0];
edit82.Text:=A[1];
end;
end;
的錯誤信息是:
First chance exception at $7C812FD3. Exception class EStringListError with message 'List index out of bounds (2)'. Process paligs.exe (732)
林試圖從字符串中的所有單詞edit81領域和數字編輯82場。
我的形象從形式:http://i.stack.imgur.com/7vnS8.jpg
現在是時候開始給您的控件比'edit82'更好的名字了。和時間開始縮進你的代碼。 –