Autor Beitrag
jagdfalke
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Di 28.06.05 21:03 
Wenn ich mich richtig erinnere gibts in PHP eine Funktion an die ich einen String und ein Trennzeichen übergebe und der dann den String anhand der Trennzeichen in ein array schreibt. Gibts das auch für Delphi?

also des schaut dann so aus in php:
string = "hello:world";
array = namederfunktion(string, ":");

dann wäre array[0] = hello und array[1] = world.

mfg
jagdfalke
delfiphan
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 2684
Erhaltene Danke: 32



BeitragVerfasst: Di 28.06.05 21:05 
Such mal im Forum nach Explode.
jagdfalke Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Di 28.06.05 21:44 
Ich bekomme die Funktion die ich im Forum gefunden habe nicht ans laufen. Hier mal der Code:
Ich lass mal Prozedure und Funktionen die nichts mit dem Problem zu tun haben weg.
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:
93:
94:
95:
96:
97:
98:
99:
100:
101:
102:
103:
104:
105:
106:
107:
108:
109:
110:
111:
112:
113:
114:
115:
116:
117:
118:
119:
120:
121:
122:
123:
124:
125:
126:
127:
128:
129:
130:
131:
132:
133:
134:
135:
136:
137:
138:
139:
140:
unit main_unit;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, Menus, StdCtrls, CPort, ComCtrls, ExtCtrls, StrUtils;

type
   TStringDynArray = Array of String;
  TFrm_Main = class(TForm)
    MainMenu1: TMainMenu;
    Datei1: TMenuItem;
    Open1: TMenuItem;
    Close1: TMenuItem;
    Settings1: TMenuItem;
    Datei2: TMenuItem;
    Close2: TMenuItem;
    ComPort1: TComPort;
    ools1: TMenuItem;
    Terminal1: TMenuItem;
    Panel1: TPanel;
    GroupBox1: TGroupBox;
    Label1: TLabel;
    Label2: TLabel;
    Label3: TLabel;
    Label4: TLabel;
    Label5: TLabel;
    Label6: TLabel;
    Label7: TLabel;
    Label8: TLabel;
    Label9: TLabel;
    Label10: TLabel;

    procedure Close2Click(Sender: TObject);
    procedure Open1Click(Sender: TObject);
    procedure Close1Click(Sender: TObject);
    procedure FormCreate(Sender: TObject);
    procedure Settings1Click(Sender: TObject);
    procedure Terminal1Click(Sender: TObject);
    procedure FormResize(Sender: TObject);
    procedure ComPort1RxChar(Sender: TObject; Count: Integer);
    procedure FormClose(Sender: TObject; var Action: TCloseAction);
    function Explode(const Separator, S: string; Limit: Integer = 0): TStringDynArray;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Frm_Main: TFrm_Main;
  Serial_in: String;

implementation

uses terminal_unit;

{$R *.dfm}


procedure TFrm_Main.ComPort1RxChar(Sender: TObject; Count: Integer);
var
        Str: String;
        position: integer;
        type_of_input: String;
        exparr: TStringDynArray;
const
        strUmbruch = #13 + #10;
begin

        {INPUT SOLANGE BUFFERN BIS EIN ZEILENUMBRUCH KOMMT}
        ComPort1.ReadStr(Str, Count);
        Serial_in := Serial_in + Str;

        position := pos(strUmbruch, Serial_in);

        if position <> 0 then
                begin
                Delete(Serial_in, length(Serial_in)-1, length(serial_in));

                //INPUT WURDE BEENDET UND MUSS JETZT AUSGEWERTET WERDE
                //frm_Terminal.listbox1.Items.Add(Serial_in);
                //frm_Terminal.listbox1.ItemIndex := frm_Terminal.listbox1.Count - 1;

                type_of_input := LeftStr(Serial_in, 3);

                if type_of_input = 'Pos' then
                begin
                        //POSITIONS STRING AUSWERTEN UND ANZEIGEN
                        //frm_Terminal.listbox1.Items.Add('Positions Reveiced');
                        //frm_Terminal.listbox1.ItemIndex := frm_Terminal.listbox1.Count - 1;
                        exparr := explode(':', Serial_in);
                                              
                end;

                Serial_in := '';
        end;
end;


function Explode(const Separator, S: string; Limit: Integer = 0): TStringDynArray;
var
  SepLen: Integer;
  F, P: PChar;
  ALen, Index: Integer;
begin
  SetLength(Result, 0);
  if (S = '') or (Limit < 0) then Exit;
  if Separator = '' then
  begin
    SetLength(Result, 1);
    Result[0] := S;
    Exit;
  end;
  SepLen := Length(Separator);
  ALen := Limit;
  SetLength(Result, ALen);

  Index := 0;
  P := PChar(S);
  while P^ <> #0 do
  begin
    F := P;
    P := StrPos(P, PChar(Separator));
    if (P = nil) or ((Limit > 0) and (Index = Limit - 1)) then P := StrEnd(F);
    if Index >= ALen then
    begin
      Inc(ALen, 5); // mehrere auf einmal um schneller arbeiten zu können
      SetLength(Result, ALen);
    end;
    SetString(Result[Index], F, P - F);
    Inc(Index);
    if P^ <> #0 then Inc(P, SepLen);
  end;
  if Index < ALen then SetLength(Result, Index); // wirkliche Länge festlegen
end;


end.

Der Debugger sagt:
[Waring]: Variable 'exparr' might not have been initialized
[Error]: Unsatisfied forwart or external declaration
[Warning]: Could not compile

Kann jemand helfen?

mfg
jagdfalke

Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt.


Zuletzt bearbeitet von jagdfalke am Di 28.06.05 21:47, insgesamt 1-mal bearbeitet
Kroni
ontopic starontopic starontopic starontopic starontopic starofftopic starofftopic starofftopic star
Beiträge: 720

Win 98, Win ME, Win2k, Win XP
D3 Pro
BeitragVerfasst: Di 28.06.05 21:44 
oder selber schreiben!
Tino
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Veteran
Beiträge: 9839
Erhaltene Danke: 45

Windows 8.1
Delphi XE4
BeitragVerfasst: Mi 29.06.05 08:51 
Guten Morgen!

Wenn du die Explode in die Form-Deklaration packst...
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
  TFrm_Main = class(TForm)
[...]
    function Explode(const Separator, S: string; Limit: Integer = 0): TStringDynArray;
  private
    { Private declarations }
  public
    { Public declarations }
  end;

Dann musst du die Funktion auch so implementieren das diese dem Form "gehört". Klingt komisch - ist aber so. ;-) Wichtig ist also, dass du an der Stelle wo du die Funktion implementierst auch das TFrm_main angibst:
ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
[...]
                Serial_in := '';
        end;
end;


function TFrm_main.Explode(const Separator, S: string; Limit: Integer = 0): TStringDynArray;
var
  SepLen: Integer;
  F, P: PChar;
  ALen, Index: Integer;
begin
  SetLength(Result, 0);
[...]

Gruß
Tino
MitschL
ontopic starontopic starontopic starontopic starontopic starontopic starofftopic starofftopic star
Beiträge: 211

Win 98 SE, Win 2000
D5 Pers, D6 Pers und D7 Pro
BeitragVerfasst: Mi 29.06.05 09:17 
Auch Moin,

die Warnung mit der Variable 'exparr' rührt daher, daß du ihr lediglich in einer Bedingung einen Wert zuweist, sonst aber nicht. Wird die Bedingung nicht erfüllt ist 'expaar' undefiniert.
Du solltest diese Variable vielleicht initialisieren, wenn du sie später auch mal nutzt.

gegrüßt!

_________________
"Bloßes Ignorieren ist noch keine Toleranz." (Theodor Fontane)
J.Borchert
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starontopic star
Beiträge: 150

WIN10
XE2 Professional
BeitragVerfasst: Mi 29.06.05 18:54 
Vielleicht hilft Dir dies:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
6:
7:
8:
9:
10:
11:
12:
13:
14:
15:
16:
17:
18:
19:
function StrX(const Trenner:Char; s:string; x:integer):string; //Sucht X-ten String in s
  var sl:TStringList;
    begin sl:=TStringList.Create;// Die Liste nimmt die einzelnen Strings auf
          // siehe Online.Hilfe ExtractStrings (so kommen die Strings in sl
          // -1 weil jede sl mit 0 beginnt
          if ExtractStrings([Trenner],[' '],PChar(s),sl)>= x-1 then
            //     z.B. Leerzeichen   am Anf.ignorieren Quelle Liste
            result:= Trim(AnsiDequotedStr(sl[x-1],'"')) else result:='';
           // im Ergebnis steht so das X-te Wort der Zeile s
          sl.Free;
    end;
 (* Aufruf und Beispiel:

    s:='Es kann vielleicht "Ohne Worte" sein aber nicht ohne Punkt.';
    Trenner:=#32;  // Leerzeichen
    x:=4;

    s:= StrX(Trenner,s,x);  // s = 'Ohne Worte'
 *)


mfG Jürgen

_________________
Wer immer macht was er schon kann, bleibt immer das, was er schon ist. "H.Ford"
jagdfalke Threadstarter
Hält's aus hier
Beiträge: 13



BeitragVerfasst: Mi 29.06.05 19:06 
habs geschaft, danke.