Autor Beitrag
Biarchiv
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 688



BeitragVerfasst: Mo 03.10.05 16:33 
Hallo,

delphianer, folgender Code funtioniert sehr gut nur folgendes Problem.
Wenn dvdoption.memo1.lines[f] normale Strings (Texte) enthält läuft dieser
Code super.

Nur müssen 00h zwischen jeden Buchstaben reingenommen werden.
im String normal: MEINString in M E I N S t r i n g umwandel wo " " ein 00h wert sein muss.

So geht es leider nicht mit 00h:

ausblenden Delphi-Quelltext
1:
2:
3:
4:
5:
    for i1 := 0 to (Length(dvdoption.memo1.lines[f])) do
    begin
    r := r + dvdoption.memo1.lines[f][i1];
    r := r + #0;
    end;


Kompletter Code

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:
procedure FindSignature;
var f,i1 : integer;
pos : int64;
r,w : string;
fs: TFileStream;
begin
w := #255;

for f := 0 to (dvdoption.memo1.lines.count) do
begin

    for i1 := 0 to (Length(dvdoption.memo1.lines[f])) do
    begin
    r := r + dvdoption.memo1.lines[f][i1];
    r := r + #0;
    end;

//r := dvdoption.memo1.lines[f];

pos := (FindSignatureInFile(Form1.Edit1.text, r, false));

if not (pos = -1) then
  begin
  fs := TFileStream.Create(Form1.Edit1.text, fmopenreadwrite or fmsharedenynone);
  fs.Seek(pos - 19, soFromBeginning);
  fs.write(w, 2);
  fs.Free;
  end;


end;
end;


Moderiert von user profile iconraziel: Code- durch Delphi-Tags ersetzt
MSCH
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 1448
Erhaltene Danke: 3

W7 64
XE2, SQL, DevExpress, DevArt, Oracle, SQLServer
BeitragVerfasst: Mo 03.10.05 16:49 
Isch schätze, da spielt windows nicht mit (wo ja das TMemo abgeleitet wird), da #0 immer das Stringende definiert.
Das Pascal-Pendant Shortstring, wo das mit der #0 funktioniert, kennt windows nicht.

Ich würde ein dynamisches Array of Char o. Byte verwenden, den gewünschten String reinkopieren und die nullen ebenfalls.
Ansonsten fällt mir spontan widestring, utfstring etc. ein, die damit umgehen könnten.
grez
msch

_________________
ist das politisch, wenn ich linksdrehenden Joghurt haben möchte?
Biarchiv Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 688



BeitragVerfasst: Sa 08.10.05 09:40 
Hey,

ich habe nun SearchWord auf WideString umgeändert.
ausblenden Delphi-Quelltext
1:
2:
        if (Buffer[i] = SearchWord[idx]) then
          Inc(idx)

hier sagt er das die Operation auf SearchWord nicht anwenbar sei,
eine andere Lösung?

So sollte es dann funtionieren das auch nach 00h Werten
in Dateien gesucht werden können, oder?


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:
function FindSignatureInFile(const FileName   : string;
                    SearchWord : widestring; MatchCase : Boolean) : Integer;
var
  fs     : TFileStream;
  Buffer : array [1..10000] of Char;
  Size   : Int64;
  idx    : Integer;
  i      : Integer;
begin
  randomize;
  Result := -1;
  idx := 1;
  if not MatchCase then
   SearchWord := UpperCase(SearchWord);
  fs := TFileStream.Create(filename, fmopenreadwrite or fmsharedenynone);
  try
    Repeat
     if (random(200) = 100) then Application.ProcessMessages;
     Size := (Fs.Size - Fs.Position);
      if Size > 10000 then Size := 10000;
      Fs.ReadBuffer(Buffer, Size);
      if not MatchCase then
      begin
        for i := 1 to Size do
          Buffer[i] := Uppercase(Buffer)[i];
      end;
      for i := 1 to Size do
      begin
        if (Buffer[i] = SearchWord[idx]) then
          Inc(idx)
        else
          idx := 1;
        if (idx = Length(SearchWord)) then
        begin
          Result := (fs.Position - Size) + i - idx + 1;
          Exit;
        end;
      end;
    until (fs.Position >= fs.Size) or (fs.Position >= 500000);
  finally
   fs.Free;
  end;
end;

procedure FindSignature;
var f,i1 : integer;
pos : int64;
w : string;
r: Widestring;
fs: TFileStream;
begin
w := #255;

for f := 0 to (dvdoption.memo1.lines.count) do
begin

    for i1 := 0 to (Length(dvdoption.memo1.lines[f])) do
    begin
    r := r + dvdoption.memo1.lines[f][i1];
    r := r + #0;
    end;
//r := dvdoption.memo1.lines[f];

pos := (FindSignatureInFile(Form1.Edit1.text, r, false));

if not (pos = -1) then
  begin
  fs := TFileStream.Create(Form1.Edit1.text, fmopenreadwrite or fmsharedenynone);
  fs.Seek(pos - 19, soFromBeginning);
  fs.write(w, 2);
  fs.Free;
  end;


end;
end;


Moderiert von user profile iconraziel: Delphi-Tags hinzugefügt.
Biarchiv Threadstarter
ontopic starontopic starontopic starontopic starontopic starontopic starontopic starhalf ontopic star
Beiträge: 688



BeitragVerfasst: Mi 12.10.05 17:13 
Hallo,

dieser Code müßte doch nun auf 00h funktionieren, oder?

Vielen Dank...