![]() |
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:
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; |
AW: FastReport: RFT Länge ermitteln
Zitat:
Delphi-Quellcode:
Optimieren darfst du selbst.
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; Bis bald... Thomas |
AW: FastReport: RFT Länge ermitteln
Zitat:
Delphi-Quellcode:
Und so im Bericht eingesetzt werden:
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.
Delphi-Quellcode:
Bis bald...
procedure DetailDataOnBeforePrint(Sender: TfrxComponent);
begin Child.Visible := not IsRTFTextEmpty(<data."RTFData">); end; Thomas |
Alle Zeitangaben in WEZ +1. Es ist jetzt 12:21 Uhr. |
Powered by vBulletin® Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO © 2011, Crawlability, Inc.
Delphi-PRAXiS (c) 2002 - 2023 by Daniel R. Wolf, 2024-2025 by Thomas Breitkreuz