Einzelnen Beitrag anzeigen

AlexII

Registriert seit: 28. Apr 2008
1.717 Beiträge
 
FreePascal / Lazarus
 
#10

Re: Meine Drag'n'Drop-Funktion ergänzen

  Alt 1. Apr 2010, 17:54
Hab jetzt ein Problem, welches ich nicht lösen kann.
Und zwar ich lade die Daten per Import und will auch per Drag'n'Drop, siehe Code.

Bei der Lösung per Drag'n'Drop bekomme ich als die Fehlermeldung
Zitat:
Listenindex überschreitet das Maximum(1)
Was kann das den sein? Beim Importieren bekomm ich die aber nicht.

Delphi-Quellcode:
//Import
procedure TForm1.ChannelListImport1Click(Sender: TObject);
var i: Integer;
    List : TStringList;
    List2: TStringList;
begin
if OpenDialog1.Execute then
begin
  List:=TStringList.Create;
  try
    List.LoadFromFile(OpenDialog1.FileName);

    if ListBox1.Count<>0 then
    begin
    if MessageDlg(_('Retain existing radio stations list?'), mtInformation, [mbYes, mbNo], 0) = mrNo then
    begin
    ListBox1.Clear;
    ListBox2.Clear;
    ListBox3.Clear;
    ListBox4.Clear;
    end;
    end;

    if ExtractFileExt(OpenDialog1.Filename)='.crpthen
    begin
    for i:=0 to List.Count-1 do
    begin
    List2:=Explode('<>', List[i]);
    ListBox1.Items.Insert(i, List2[1]);
    ListBox2.Items.Insert(i, List2[2]);
    ListBox3.Items.Insert(i, List2[3]);
    ListBox4.Items.Insert(i, List2[4]);
    List2.Free;
    end;
    end else
        begin
        for i:=0 to List.Count-1 do
        begin
        List2:=Explode('=', List[i]);
        ListBox1.Items.Insert(i, List2[1]);
        ListBox2.Items.Insert(i, List2[2]);
        ListBox3.Items.Insert(i, List2[3]);
        ListBox4.Items.Insert(i, List2[4]);
        List2.Free;
        end;
        end;

  finally
    List.Free;
  end;
end;
end;
Delphi-Quellcode:
//Und hier per Drag'n'Drop
procedure TForm1.WMDROPFILES(var Msg: TMessage);
var j, count: Cardinal;
    Buffer: String;
    i: Integer;
    List : TStringList;
    List2: TStringList;
begin
  inherited;
  Buffer := '';
  count := DragQueryFile(Msg.WParam, $FFFFFFFF, nil, 0);
  for j := 0 to count - 1 do
    begin
      SetLength(Buffer, DragQueryFile(Msg.WParam, j, nil, 0) + 1);
      DragQueryFile(Msg.WParam, j, @Buffer[1], Length(Buffer));
    end;

//Laden
List:=TStringList.Create;
  try
    List.LoadFromFile(Buffer);

    if ListBox1.Count<>0 then
    begin
    if MessageDlg(_('Retain existing radio stations list?'), mtInformation, [mbYes, mbNo], 0) = mrNo then
    begin
    ListBox1.Clear;
    ListBox2.Clear;
    ListBox3.Clear;
    ListBox4.Clear;
    end;
    end;

    if ExtractFileExt(Buffer)='.crpthen
    begin
    showmessage(inttostr(ListBox1.Count));
    for i:=0 to List.Count-1 do
    begin
    showmessage(inttostr(ListBox1.Count));
    List2:=Explode('<>', List[i]);
    ListBox1.Items.Insert(i, List2[1]);
    ListBox2.Items.Insert(i, List2[2]);
    ListBox3.Items.Insert(i, List2[3]);
    ListBox4.Items.Insert(i, List2[4]);
    List2.Free;
    end;
    end else
        begin
        for i:=0 to List.Count-1 do
        begin
        List2:=Explode('=', List[i]);
        ListBox1.Items.Insert(i, List2[1]);
        ListBox2.Items.Insert(i, List2[2]);
        ListBox3.Items.Insert(i, List2[3]);
        ListBox4.Items.Insert(i, List2[4]);
        List2.Free;
        end;
        end;

  finally
    List.Free;
  end;
end;
Bin Hobbyprogrammierer! Meine Fragen beziehen sich meistens auf Lazarus!
  Mit Zitat antworten Zitat