Delphi-PRAXiS
Seite 2 von 2     12   

Delphi-PRAXiS (https://www.delphipraxis.net/forum.php)
-   Sonstige Werkzeuge (https://www.delphipraxis.net/63-sonstige-werkzeuge/)
-   -   FastReport: RFT Länge ermitteln (https://www.delphipraxis.net/212430-fastreport-rft-laenge-ermitteln.html)

haentschman 10. Feb 2023 13:16

AW: FastReport: RFT Länge ermitteln
 
Danke...:P

Diese Varianten habe ich alle durch. :? Ich bin nie zu einem stabilen Ergebnis gekommen. Erst Recht nicht mit dem Bug in if/then. :cry:

TRIM hat bei mir alle Zeichen, auch die benötigten, entfernt -> Lenght = 0 :?
Zitat:

Lines.Text (unter Windows) immer mindestens = 2
...nicht ganz. Wenn du imho auf ein NULL Feld triffst ist, Lines.Count = 0 und Länge = 0 :wink:

Ich habe jetzt eine CustomerFunction eingebaut, die mir im Delphi Quelltext das Datenfeld in das Dummy RichEdit einliest und mir den Text ohne Steuerzeichen emittelt und einen Boolean zurückgibt. :wink: Damit funktioniert es stabil...:thumb:
Delphi-Quellcode:
function TdmReport.frxReport1UserFunction(const MethodName: string; var Params: Variant): Variant;
begin
  if MethodName = 'CANSHOWCHILD' then
  begin
    Result := CanShowChild(Params[0], Params[1]);
  end;
end;
...
function TdmReport.CanShowChild(DataSetName, FieldName: string): Boolean;
var
  Data: TDataSet;
begin
  Result := False;

  if FCurrentPrint.ReportDictionaryDataSets.ContainsKey('frx' + DataSetName) then
  begin
    Data := FCurrentPrint.ReportDictionaryDataSets['frx' + DataSetName];
    if Assigned(Data) then
    begin
      Stream.Clear;
      TBlobField(Data.FieldByName(Fieldname)).SaveToStream(Stream);
      Stream.Position := 0;
      Rich.Lines.LoadFromStream(Stream);

      Result := (Trim(Rich.Lines.Text) > '');
    end;
  end;
end;

mytbo 10. Feb 2023 16:41

AW: FastReport: RFT Länge ermitteln
 
Zitat:

Zitat von haentschman (Beitrag 1518509)
Delphi-Quellcode:
(Dummy.RichEdit.Lines.Count > 0);
Funktioniert nicht. Weil 5 Lines keinen Inhalt haben können...sondern nur LineFeeds. :zwinker:

Delphi-Quellcode:
procedure DetailDataOnBeforePrint(Sender: TfrxComponent);
var
  i: Integer;
  isVisible: Boolean;
begin
  isVisible := False;
  for i := 0 to Dummy.RichEdit.Lines.Count - 1 do
  begin
    isVisible := (Dummy.RichEdit.Lines[i] <> '');
    if isVisible then Break;
  end;

  Child.Visible := isVisible;
end;
Optimieren darfst du selbst.

Bis bald...
Thomas

mytbo 13. Feb 2023 00:19

AW: FastReport: RFT Länge ermitteln
 
Zitat:

Zitat von haentschman (Beitrag 1518531)
Ich habe jetzt eine CustomerFunction eingebaut, die mir im Delphi Quelltext das Datenfeld in das Dummy RichEdit einliest und mir den Text ohne Steuerzeichen emittelt und einen Boolean zurückgibt.

Wenn immer möglich, sollte eine Bericht-Funktion ohne interne Abhängigkeiten geschrieben werden. Das bietet die Möglichkeit, mit der Zeit eine eigene Sammlung nützlicher Helfer zu erstellen, die nur durch Einbindung einer Unit zur Verfügung gestellt werden. Im konkreten Fall könnte es zum Beispiel so aussehen:
Delphi-Quellcode:
unit u_ReportFunctions;

interface

uses
  Windows, Messages, SysUtils, Classes, Variants,
  fs_iinterpreter;

type
  TReportFunctions = class(TfsRTTIModule)
  private
    function CallMethod(pmInstance: TObject; pmClassType: TClass;
      const pmcMethodName: String; pmCaller: TfsMethodHelper): Variant;
  public
    constructor Create(pmScript: TfsScript); override;
  end;

implementation

uses
  frxClass, frxVariables, frxRichEdit;

const
  OWN_FUNCTIONS = 'Own functions';

function RTFTextCharCount(const pmcRTFText: String): Integer;
var
  richEdit: TRxRichEdit;
  loadStream: TStringStream;
begin
  Result := 0;
  if pmcRTFText = '' then Exit; //=>

  richEdit := TRxRichEdit.CreateParented(HWND(HWND_MESSAGE));
  try
    loadStream := TStringStream.Create(pmcRTFText);
    try
      richEdit.Lines.LoadFromStream(loadStream);
    finally
      loadStream.Free;
    end;

    Result := richEdit.GetTextLen;
    if Result > 0 then
      Result := Result - (richEdit.Perform(EM_GETLINECOUNT, 0, 0) - 1);
  finally
    richEdit.Free;
  end;
end;

function IsRTFTextEmpty(const pmcRTFText: String): Boolean;
begin
  if pmcRTFText <> '' then
    Result := (RTFTextCharCount(pmcRTFText) = 0)
  else
    Result := True;
end;

//=== TReportFunctions =========================================================

constructor TReportFunctions.Create(pmScript: TfsScript);
begin
  inherited Create(pmScript);
  pmScript.AddMethod('function IsRTFTextEmpty(const pmcRTFText: String): Boolean',
    CallMethod, OWN_FUNCTIONS, 'IsRTFTextEmpty() returns if chars are present');
  pmScript.AddMethod('function RTFTextCharCount(const pmcRTFText: String): Integer;',
    CallMethod, OWN_FUNCTIONS, 'RTFTextCharCount() returns the number of chars');
end;

function TReportFunctions.CallMethod(pmInstance: TObject; pmClassType: TClass;
  const pmcMethodName: String; pmCaller: TfsMethodHelper): Variant;
begin
  if SameText(pmcMethodName, 'IsRTFTextEmpty') then
    Result := IsRTFTextEmpty(pmCaller.Params[0])
  else if SameText(pmcMethodName, 'RTFTextCharCount') then
    Result := RTFTextCharCount(pmCaller.Params[0]);
end;

initialization
  fsRTTIModules.Add(TReportFunctions);

end.
Und so im Bericht eingesetzt werden:
Delphi-Quellcode:
procedure DetailDataOnBeforePrint(Sender: TfrxComponent);
begin
  Child.Visible := not IsRTFTextEmpty(<data."RTFData">);
end;
Bis bald...
Thomas


Alle Zeitangaben in WEZ +1. Es ist jetzt 04:35 Uhr.
Seite 2 von 2     12   

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024 by Thomas Breitkreuz