Autor Beitrag
JayEff
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Do 28.04.05 23:33 
Hi Leute.
Ich bekomme beim Ausführen einer FindFirst/FindNext prozedur in meiner Dll immer einen fehler! Das Compilieren beider teile klappt, nur beim ausführen des Codes kommt erstmal die gängige EConvertError (kein TStringList nach TStringList) nachricht. Warum kann ich keine TStringList zu einer TStringList zuweisen?
Die DLL:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
Library WinampAPI;
{$WARN UNIT_PLATFORM OFF}
Uses
    FastShareMem,
    SysUtils,
    Classes,
    Windows,
    ShellAPI,
    FileCtrl,
    WinAmpCtr;

Var
    Dirs: TStringList;
    WM: TWinampCtr;
    {$R *.res}

{...}
Function FindPLs(Directory: String): TStringList Stdcall;
Var
    SR: TSearchRec;
Begin
    result := TStringList.Create;
    FindFirst(Directory + '\*.m3u', faAnyFile, SR);
    Dirs.Add(Directory);
    result.Add(SR.Name);
    While FindNext(SR) = 0 Do
    Begin
        result.Add(SR.Name);
        Dirs.Add(Directory);
    End;
End;

Function ReplaceM3U(List: String): String Stdcall;
Begin
    result := StringReplace(List, '.m3u''', [rfReplaceAll]);
End;

Exports ReplaceM3U,
    FindPLs,
    Execute,
    getFilename,
    Winampctrl_init,
    Winampctrl_free,
    PlayState,
    StartWinamp,
    NextTrack,
    PrevTrack,
    started,
    PlayingRandom,
    shuffle,
    Trackdata,
    State;

End.

Mit folgendem Code rufe ich die Prozedur aus der dll auf:
ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
77:
78:
79:
80:
81:
82:
83:
84:
85:
86:
87:
88:
89:
90:
91:
92:
Unit Unit1;

Interface
{$WARN UNIT_PLATFORM OFF}
Uses
    FastShareMem,
    Windows,
    Messages,
    SysUtils,
    Variants,
    Classes,
    Graphics,
    Controls,
    Forms,
    Dialogs,
    StdCtrls,
    FileCtrl,
    WinAmpCtr,
    ComCtrls,
    ShellAPI,
    ExtCtrls;
{...}
Function ReplaceM3U(List: String): String Stdcallexternal 'WinampAPI.dll';
Function FindPLs(Directory: String): TStringList Stdcallexternal 'WinampAPI.dll';
Procedure Execute(FileName: StringStdcallexternal 'WinampAPI.dll';
Function getFilename(Directorys, Names: TStringList; Index: Integer): String Stdcallexternal 'WinampAPI.dll';
Procedure PlayState(State: StringStdcallexternal 'WinampAPI.dll';
Procedure StartWinamp(Yes: Boolean) Stdcallexternal 'WinampAPI.dll';
Procedure PrevTrack; Stdcallexternal 'WinampAPI.dll';
Procedure NextTrack; Stdcallexternal 'WinampAPI.dll';
Procedure Winampctrl_free; Stdcallexternal 'WinampAPI.dll';
Procedure Winampctrl_init; Stdcallexternal 'WinampAPI.dll';
Function started: Boolean Stdcallexternal 'WinampAPI.dll';
Function PlayingRandom: Boolean Stdcallexternal 'WinampAPI.dll';
Procedure shuffle(Activate: Boolean) Stdcallexternal 'WinampAPI.dll';
Function Trackdata: TStringList Stdcallexternal 'WinampAPI.dll';
Function State: String Stdcallexternal 'WinampAPI.dll';

Var
    Form1: TForm1;
    Dirs: TStringList;
Implementation

{$R *.dfm}

{
Interessant: In der DLL steht genau DIESER Code. Benutze ich aber den Code aus meiner Unit, statt die function der DLL, klappt es.
Function FindPLs(Directory: String): TStringList Stdcall;
Var
    SR: TSearchRec;
Begin
    result := TStringList.Create;
    FindFirst(Directory + '\*.m3u', faAnyFile, SR);
    Dirs.Add(Directory);
    result.Add(SR.Name);
    While FindNext(SR) = 0 Do
    Begin
        result.Add(SR.Name);
        Dirs.Add(Directory);
    End;
End;}


Procedure TForm1.Button2Click(Sender: TObject);
Var
    Directory: String;
    S: TStringList;
    i: Integer;
Begin
    S := TStringList.Create;
    If SelectDirectory('Playlists laden''', Directory) Then
    Begin
        S.Assign(FindPLs(Directory)); //<- Hier wird der Fehler stecken..? oO
        For i := 1 To S.Count Do //<- grüner Pfeil
            Dirs.Add(Directory);
        ListBox1.Items.Commatext := ReplaceM3U(S.Commatext);
    End;
    S.Free;
End;

Procedure TForm1.FormCreate(Sender: TObject);
Begin
    Winampctrl_init;
    Dirs := TStringList.Create;
    Timer1.Enabled := started;
End;

Procedure TForm1.FormClose(Sender: TObject; Var Action: TCloseAction);
Begin
    Winampctrl_free;
    Dirs.Free;
End;
End.


Danke schonmal Leute :D

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.


Zuletzt bearbeitet von JayEff am Fr 29.04.05 00:24, insgesamt 1-mal bearbeitet
JayEff Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 29.04.05 00:17 
OOOK. Es lag daran, dass die erste Unit in der PROJEKTDATEI kein Fastsharemem war sondern "Forms"! Nun kann ich ja wieder zur wichtigstens meiner Fragen zurückkehren. *ersten post änderts*

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
JayEff Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 29.04.05 17:32 
Sacht mal Leute? Sind meine Fragen so kompliziert? Formuliere ich sie falsch? Bin ich dumm, und ihr wollt mich selbst draufkommen lassen? Könnt ihr mich nicht leiden??

Ich frag nur desshalb so, weil auf meine letzten paar Fragen einfach keine Lösungen kamen. manchmal wurde es versucht, aber nie kam ne Lösung raus. und jetzt bekomm ich nichtmal EINE antwort. Irgentwas mach ich falsch, da bin ich mir sicher. aber was? könnt ihr mir nich wenigstens das sagen?

(Sorry falls das als Schiebeposting gilt, wenn ihr wollt poste ich die gleiche Frage mal inner Offtopic...)

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.
Sprint
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 849



BeitragVerfasst: Fr 29.04.05 19:15 
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
program Project1;

uses
  FastShareMem in 'FastShareMem.pas',
  Forms,
  Unit1 in 'Unit1.pas' {Form1};

{$R *.res}

begin
  Application.Initialize;
  Application.CreateForm(TForm1, Form1);
  Application.Run;
end.


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
44:
45:
46:
47:
48:
49:
50:
51:
52:
53:
54:
55:
56:
57:
58:
59:
60:
61:
62:
63:
64:
65:
66:
67:
68:
69:
70:
71:
72:
73:
74:
75:
76:
unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, StdCtrls;

type
  TForm1 = class(TForm)
  {...}
  private
    { Private-Deklarationen }
    Dirs: TStringList;
  public
    { Public-Deklarationen }
  end;

var
  Form1: TForm1;

function FindPLs(const Directory: String): TStringList;
function ReplaceM3U(const List: String): String;

implementation

{$R *.dfm}

uses
  FileCtrl;

const
  WinampAPI = 'WinampAPI.dll';

function FindPLs; external WinampAPI name 'FindPLs';
function ReplaceM3U; external WinampAPI name 'ReplaceM3U';

{--------------------------------------------------------------------------------------------------}

procedure TForm1.FormCreate(Sender: TObject);
begin

  Dirs := TStringList.Create;

end;

{--------------------------------------------------------------------------------------------------}

procedure TForm1.FormDestroy(Sender: TObject);
begin

  Dirs.Free;

end;

{--------------------------------------------------------------------------------------------------}

procedure TForm1.Button2Click(Sender: TObject);
var
  Directory: String;
  PlayLists: TStringList;
begin

  if SelectDirectory('''', Directory) then
  begin
    PlayLists := FindPLs(Directory);
    Dirs.AddStrings(PlayLists);
    ListBox1.Items.CommaText := ReplaceM3U(PlayLists.CommaText);
    PlayLists.Free;
  end;

end;

{--------------------------------------------------------------------------------------------------}

end.


ausblenden volle Höhe Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
20:
21:
22:
23:
24:
25:
26:
27:
28:
29:
30:
31:
32:
33:
34:
35:
36:
37:
38:
39:
40:
41:
42:
43:
library WinampAPI;

uses
  FastShareMem in 'FastShareMem.pas',
  SysUtils,
  Classes;

{$R *.res}

{--------------------------------------------------------------------------------------------------}

function FindPLs(const Directory: String): TStringList;
var
  SR: TSearchRec;
begin

  Result := TStringList.Create;
  if FindFirst(IncludeTrailingPathDelimiter(Directory) + '*.m3u', faAnyFile, SR) = 0 then
  begin
    repeat
      Result.Add(SR.Name);
    until FindNext(SR) <> 0;
    FindClose(SR);
  end;

end;

{--------------------------------------------------------------------------------------------------}

function ReplaceM3U(const List: String): String;
begin

  Result := StringReplace(List, '.m3u''', [rfReplaceAll]);

end;

{--------------------------------------------------------------------------------------------------}

exports
  FindPLs,
  ReplaceM3U;

end.

_________________
Ciao, Sprint.
JayEff Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starofftopic star
Beiträge: 2971

Windows Vista Ultimate
D7 Enterprise
BeitragVerfasst: Fr 29.04.05 19:44 
[Fehler] WinampAPI.dpr(180): Inkompatible Typen: 'Cardinal' und 'TSearchRec'
in der linie FindClose(SR);

Was genau hast du anders gemacht? Ausser das Stdcall weglassen. Lag es denn vielleicht daran?
[edit] Hatte wohl vergessen irgenteine Unit einzubinden... Jetzt gehts xD
Aber der EConvertError kommt immernoch. TStringlist kann nicht zu TStringList zugewiesen werden. Könnte wohl jemand den Code ausprobieren?[/edit]

[edit]Ui jetzt gehts O_O Immer wird mir gesagt, ich soll Assign verwenden statt S:=FindPLs(Directory); aber kaum benutz ichs, klappts ganz absolut perfekt O_O[/edit]

_________________
>+++[>+++[>++++++++<-]<-]<++++[>++++[>>>+++++++<<<-]<-]<<++
[>++[>++[>>++++<<-]<-]<-]>>>>>++++++++++++++++++.+++++++.>++.-.<<.>>--.<+++++..<+.