Fast Report - Get CSV Data from Memo Field

From eStream Software
Revision as of 02:31, 20 April 2018 by Twfaung (talk | contribs) (→‎Steps)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Introduction

Below is example on how to get CSV data from Maintain Agent UDF_AList field

ProjectCode;Remark
P12W5;Rmakr 1
P13W4;Note 1234

Steps

Last Script Update : 18 Dec 2015

01. Enter below script in the Code Tab
Get CSV Data Script
function SetStrictDelimiter(const AStr:String):string;
var i, x, ALength  : integer;
    s, s1 : string;
    OrigList, MasterList, Row : TStringList;                              
begin
  OrigList   := TStringList.Create;      
  MasterList := TStringList.Create;
  Row        := TStringList.Create;
  Row.Delimiter := ';';
  try
    OrigList.Text := RichTextToPlainText(AStr);                                    
    for I := 0 to OrigList.Count - 1 do
      begin
        Row.Clear;
        s1 := '';
        x := 1;
        s := OrigList[I];
        ALength := Length(s);
        while (x <= ALength) do begin
          if x = ALength then begin
            s1 := s1 + s[x];
            Row.Add(Trim(s1));
          end;
          if (s[x] = ';') then begin
              Row.Add(Trim(s1));
              s1 := '';
            end else
             s1 := s1 + s[x];           
           inc(x);
        end;
      MasterList.Add(Row.DelimitedText);
    end;
    Result := MasterList.Text;                                          
  finally
    OrigList.Free;                  
    MasterList.Free;
    Row.Free;  
  end;            
end;          
  
function ValueOfSemiColonStrEx(const AStr: string; const AIndex: integer): string;
var S: TStringList;
begin
  S := TStringList.Create;
  try
    S.Delimiter       := ';';
    S.DelimitedText   := AStr;
    if AIndex < S.Count then Result := S[AIndex]
    else Result := '';
  finally
    S.Free;
  end;
end;          

function GetAgentData(const AProject:String):String;
var S: TStringList;
    i: integer;                         
begin
  S := TStringList.Create;
  try        
    S.Text := SetStrictDelimiter(<Document_Agent."UDF_AList">);    
    for I := 0 to S.Count - 1 do begin
      if ValueOfSemiColonStrEx(S[i], 0) = AProject then //Same as Project Code CSV Column 1
        Result := ValueOfSemiColonStrEx(S[i], 1);       //Show CSV Column 2   
    end;    
  finally
    s.Free;              
  end;            
end;
FR-GetCSV-01.jpg
02. Click the Red A Icon.
03. Click on the place to be print/shown.
FR-GetCSV-02.jpg
04. Enter below Script in the memo
[GetAgentData(<Document_Detail."Project">)]
05. Click Ok button.
06. Right Click the Memo
FR-GetCSV-03.jpg
07. Select Stretch
08. File | Save As & enter New report Name after done.

See also