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.