Forum > Graphics

Text to images Generator (Console app generating bitmaps with text)

<< < (17/17)

TRon:

--- Quote from: barracuda on November 13, 2023, 12:41:18 pm ---I have question in the section of last block, where my questio is on easy key access solution.

--- End quote ---
I am not entirely sure how exactly you want to accomplish things because you did not share how you want/have the parameters stored in the config file.

However, I believe that when you wrote:

--- Code: ---for i := 0 to Pars.Count-1 do
  begin
    if Pars.Values[i][1]='-' then
      Pars.Values[i]:=copy(Pars.Values[i],2,length(Pars.Values[i]));
    Pars.Values[i] := ToLower+'='+AnsiDequotedStr(Pars.Values[i],'"'));
  end;

--- End code ---

.. is that you probably meant to write the following instead:


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---      for i := 0 to Pars.Count-1 do      begin        if Pars.Strings[i][1]='-'          then Pars.Strings[i]:=copy(Pars.Strings[i],2,length(Pars.Strings[i]));        Pars.Strings[i] := AnsiDequotedStr(Pars.Strings[i],'"');      end; .. but as said, I am not 100% sure.

What I am more sure about it that just above that when you wrote:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  Parse.Free; 
... is that you actually meant to write:

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---  Parse.Clear; 
... If not mistaken. In case mistaken then you (still) have yourself an illegal access error  :)

barracuda:
Hey I was just going to pass this and you passed the code. So this is correction suggested by chatGPT using Pars.ValueFromIndex. I originally followed this guide https://delphiprogrammingdiary.blogspot.com/2017/09/tstringlist-name-value-pair.html but it seems not to work, so I used ValueFromIndex:


--- Code: ---procedure TMyApplication.prepareParms(var Pars: TStringList);
var i: integer;
  sFN: string;
  strA: Array of String;
begin
  Pars.NameValueSeparator := '=';
  sFN := '';
  for i := 1 to paramCount do
      begin
        strA := paramStr(i).split('=');
        if strA[0][1]='-' then
          strA[0]:=copy(strA[0],2,length(strA[0]));
        Pars.Add(strA[0].ToLower+'='+AnsiDequotedStr(strA[1],'"'));
      end;
  if Pars.count>0 then
    begin
      for i := 0 to Pars.count-1 do
          begin
            if (Pars.Names[i]='configfile') OR (Pars.Names[i]='config-file') OR (Pars.Names[i]='config') then
              begin
                sFN := AnsiDequotedStr(Pars.ValueFromIndex[i],'"');
                break;
              end;
          end;
      if not fileexists(sFN) then
         writeln('File not found '+sFN)
      else
        begin
          writeln('Reading config file '+sFN);
          Pars.Free;
          Pars.LoadFromFile(sFN);
          for i := 0 to Pars.Count-1 do
              begin
                if Pars.ValueFromIndex[i][1]='-' then
                  Pars.ValueFromIndex[i]:=copy(Pars.ValueFromIndex[i],2,length(Pars.ValueFromIndex[i]));
                Pars.ValueFromIndex[i] := AnsiDequotedStr(Pars.Values[Pars.ValueFromIndex[i]],'"');
              end;

        end;
    end;
end;

--- End code ---

The config:

--- Code: ---bold
italic
characters="..."
font-family="Arial, Verdana"
font-size="9, 10, 12"

font-family="Times New Roman,Courier New"
font-size="14, 12, 10"

--- End code ---

I will continue tommorow (I did not debug it yet).

Edit:
Yes I mean .clear not .free .

barracuda:
pars stands for parameters.

It's not clear why I cannot watch the values in Debug/Add Watch or Debug/Evaluate in the private procedure. This should be not problem in Delphi 7. How does FreePascal manage. I can display the values by writeln but that is not good approach for debugging - needs to compile every time when I add the line
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---writeln(Pars.ValueFromIndex[i]);
In Debug window like Debug Inspector, etc. I always see "inavailable" Error: Member not found. Which is odd, because the member is there, but it seems like no access to private scope...

I can read variables like strA, strA[0] and sFN. But the var Pars: TStringList is passed like that:

--- Code: ---  Pars := TStringList.create;
  Pars.NameValueSeparator := '=';
  prepareParms(pars);

--- End code ---

So to debug I need to see Pars.count and other Pars members like .Names and .Values

TRon:

--- Quote from: barracuda on November 14, 2023, 01:24:15 pm ---It's not clear why I cannot watch the values in Debug/Add Watch or Debug/Evaluate in the private procedure. This should be not problem in Delphi 7. How does FreePascal manage. I can display the values by writeln but that is not good approach for debugging - needs to compile every time when I add the line
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---writeln(Pars.ValueFromIndex[i]);
In Debug window like Debug Inspector, etc. I always see "inavailable" Error: Member not found. Which is odd, because the member is there, but it seems like no access to private scope...

--- End quote ---
2 relevant threads (there are probably plenty more but these two seem to sum it up nicely):
- Inspect into TStringList
- Watching TStringList - Lazarus 3.0 (FpDebug)

And ofc. you need to have the RTL compiled with debug.

It is a work in progress....

BTW:
For all these string manipulation that you seem to be doing, have a look at unit StrUtils or the typehelper TStringHelper. It reads a lot nicer (and understandable) than those calls to copy().

barracuda:
I followed the first link and this command

--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---PStringItemList(Pars.FList)^[0]really does the job. The link is quite helpful.

Edit:
Now I see there is  Substring()


--- Code: ---public function TStringHelper.Substring(

  AStartIndex: SizeInt

):string; overload;

function TStringHelper.Substring(

  AStartIndex: SizeInt;

  ALen: SizeInt

):string; overload;
--- End code ---

Navigation

[0] Message Index

[*] Previous page

Go to full version