View Single Post
  #5  
Old 20-02-2020, 22:51
Gupta Gupta is offline
Registered User
 
Join Date: Aug 2016
Location: India
Posts: 397
Thanks: 139
Thanked 705 Times in 229 Posts
Gupta is on a distinguished road
current GetFlayByLine function is pretty hard to understand, reading the description can't we do it in this way;
and please whoever is developing current CIU please try to use meaningful variable names. L1 LN S1 doesn't make any sense
Code:
function GetFlagByLine: TArrayOfInteger;
var
  FlagDist, CurrFlagCount: String;
  I, LangCount, LangUsed, LastLineCount: Integer;
begin
  LangCount := LangNumber;
  LangUsed  := 0;
  LastLineCount := 0;
  SetArrayLength(Result, 0);
  FlagDist := GetValStr('LangBox', 'FlagByLine', '0') + ',';
  while (Length(FlagDist) > 0) and (LangUsed < LangCount) do begin
    CurrFlagCount := Trim(Copy(FlagDist, 0, Pos(',', FlagDist) - 1));
    FlagDist := Copy(FlagDist, Pos(',', FlagDist) + 1, Length(FlagDist));
    SetArrayLength(Result, GetArrayLength(Result) + 1);
    I := GetArrayLength(Result) - 1;
    Result[I] := StrToInt(CurrFlagCount);
    if Result[I] > LangCount - LangUsed then
        Result[I] := LangCount - LangUsed;
    LangUsed := LangUsed + Result[I];
    LastLineCount := Result[I];
  end;
  if LangUsed <> LangCount then
  begin
      if LastLineCount = 0 then
      begin
        SetArrayLength(Result, GetArrayLength(Result) + 1);
        Result[GetArrayLength(Result) - 1] := LangCount - LangUsed;
      end else begin
        while LangUsed <> LangCount do
        begin
            SetArrayLength(Result, GetArrayLength(Result) + 1);
            I := GetArrayLength(Result) - 1;
            Result[I] := LangCount - LangUsed;
            if Result[I] > LastLineCount then
                Result[I] := LastLineCount;
            LangUsed := LangUsed + Result[I];
        end;
      end;
  end;
end;
__________________
XD

Last edited by Gupta; 20-02-2020 at 23:01.
Reply With Quote