Einzelnen Beitrag anzeigen

Benutzerbild von ATS3788
ATS3788

Registriert seit: 18. Mär 2004
Ort: Kriftel
646 Beiträge
 
Delphi XE Starter
 
#11

AW: Datei mit FireDac "Case Sensitive" filtern

  Alt 23. Feb 2015, 17:24
Ich poste alles damit vielleicht
jemand mal einen nutzen hat.

Delphi-Quellcode:

function RTF_Stream_To_Plain_Text(Stream : TStream) : string;
var
RichEdit : TRichEdit;
begin
try
RichEdit := TRichEdit.CreateParented(HWND_MESSAGE);
RichEdit.Parent := nil;
RichEdit.PlainText := False;
RichEdit.WordWrap := false;
RichEdit.Visible := false;

Stream.Position := 0;
RichEdit.Lines.LoadFromStream(Stream);

Result := RichEdit.Lines.Text;
finally
RichEdit.Free;
end;
 end;



function DumpTable(MemTable : TFDMemTable;const UniqueInt : string) : t64Array;
var
i : Int64;
 begin
     i := 0;
      MemTable.First;
       while not MemTable.Eof do begin
        inc(i);
         SetLength(Result , i);
       Result[i-1] := MemTable.Fields.FieldByName(UniqueInt).AsLargeInt;
       MemTable.Next;
     end;
   end;


procedure FilterNoCaseSensitive(Table : TFDTable;Filter, Field2Filter, UniqueInt : string);
var
_Connection : TFDConnection;
LocalSQL : TFDLocalSQL;
MemTable : TFDMemTable;
S : string;
Stream : TStream;
arr : t64Array;
i : Integer;
begin
     Stream := TStream.Create;
     _Connection := TFDConnection.Create(nil);
     _Connection.DriverName := 'SQLite';
     LocalSQL := TFDLocalSQL.Create(nil);
     LocalSQL.Connection := _Connection;

     MemTable := TFDMemTable.Create(nil);
     MemTable.Name := 'Testtable';
     MemTable.LocalSQL := LocalSQL;

     MemTable.FieldDefs.Add(UniqueInt, ftLargeint);
     MemTable.FieldDefs.Add(Field2Filter, ftString, 1000);
     MemTable.CreateDataSet;

     LocalSQL.Active := True;
     MemTable.Active := True;

     Table.First;
     while not Table.Eof do begin
     MemTable.Insert;

     MemTable[UniqueInt] := Table[UniqueInt];
     Stream := Table.CreateBlobStream(Table.FieldByName('FELD1') , bmRead);
    S := RTF_Stream_To_Plain_Text(Stream);
    S := LowerCase(S);
      MemTable[Field2Filter] := S;
      MemTable.Post;
      Table.Next;
     end;


    Filter := LowerCase(Filter);
       MemTable.Filter := Field2Filter + ' LIKE ''%'+ Filter +'%''';
       MemTable.Filtered := False;

    MemTable.Filtered := True;

        arr := DumpTable(MemTable, UniqueInt);

   S := '';
  for i := Low(arr) to High(arr) do
   S := S + IntToStr(arr[i]) + ',';

   Delete(S,Length(S), 1);
   S := UniqueInt + ' in (' + S + ')';

   Table.Filter := S;
   Table.Filtered := True;

     MemTable.Free;
     LocalSQL.Free;
     _Connection.Free;
      Stream.Free;
   end;

FilterNoCaseSensitive(FDTable1 , 'TesT', 'FELD1', 'COUNTER');
Martin MIchael
  Mit Zitat antworten Zitat