Recent

Author Topic: [SOLVED] SynEdit for Batch Files  (Read 4183 times)

pixelink

  • Hero Member
  • *****
  • Posts: 1260
[SOLVED] SynEdit for Batch Files
« on: May 16, 2019, 01:48:51 am »
When I create a *.bat file in Notepad, and use ascii characters or special character to make lines of a box
I run the .BAT file it looks right

If I paste the same code from the .*bat file into SynEdit, SAVE IT as a *.bat file
Then I run the *.bat file, none of the boxes in the bat file look right.

Is this a UTF8 issue??

Here is my good box code in the good working BAT file.

Code: Pascal  [Select][+][-]
  1.  
  2. Echo ÉÍ Double-lined ÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ»
  3. Echo º                                                                                                º
  4. Echo º                                                                                                º
  5. Echo º                                                                                                º
  6. Echo º                                                                                                º
  7. Echo ÈÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍͼ
  8.  
  9.  
  10.  

Here is a screen between the good and bad
« Last Edit: May 17, 2019, 01:22:55 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #1 on: May 16, 2019, 01:50:56 am »
So, basically it looks like it converts my special characters to "?"'s
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #2 on: May 16, 2019, 02:13:56 am »
What ever the solution may be, my end-game is to save the correct text from the SynFile

I am  using this code for saving...
sDlg means Dialog component

Code: Pascal  [Select][+][-]
  1.  
  2. synEdit.Lines.SaveToFile(sDlg.Filename);
  3.  
  4.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

jamie

  • Hero Member
  • *****
  • Posts: 6090
Re: SynEdit for Batch Files
« Reply #3 on: May 16, 2019, 03:12:47 am »
maybe you could assign the LINES to another TStringList and then use UTF8ToWinCP(YourString);

Lets see if I can vision this..

MyStringList.Assign(UTF8toWinCP(SynEdit.Lines.Text));

MySringList.SaveTofile(….

UTF8ToWInCP is in LazUTF8 unit.
The above is not tested.
The only true wisdom is knowing you know nothing

engkin

  • Hero Member
  • *****
  • Posts: 3112
Re: SynEdit for Batch Files
« Reply #4 on: May 16, 2019, 05:10:30 am »
UTF8ToConsole instead of UTF8ToWinCP?

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #5 on: May 16, 2019, 01:27:06 pm »
Okay... i will look into these suggestions.

Just one q:
Why or can  the SynEdit be setup to except UTF8 characters by default??

Is there some code i can put in Form.Create to make the editor UTF8 compatible before it is even used?
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #6 on: May 16, 2019, 02:12:17 pm »
After some research it seems this is more of a UniCode issues than just UTF8... not sure though
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #7 on: May 16, 2019, 02:32:17 pm »
My first initial "Simple" test worked...
Now, I can now put it in a TStringList for SynEdit conversion.

Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.  uStr: String;
  4. begin
  5.   uStr:='ßßßßßß';
  6.   showmessage(ConvertEncoding(uStr, 'Ansi', 'UTF-8'));
  7.  
  8.  
  9.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #8 on: May 16, 2019, 03:07:29 pm »
Okay... got the conversion code in place (see below)

It saves it correctly visually at least.

Follow carefully...

1) The *bat code typed in Notepad working correctly in CMD  (see screenshot)
2) Copy the working code to SynEdit and it saves the exact text at least visually perfect. (see screenshot)
3) The "Good" code (from notepad) works when I run the *BAT file.  (see screenshot)
4) The "Bad" code from SynEdit, saved to bat file, and then RUn BAT file... doesn't work  (see screenshot)

So, even if the file saves visually correct, it still doesn't work.

There is something about SynEdit that is not saving to a file just like Notepad saves to a file... what's the difference??

CONVERSION CODE (which visually works):

Code: Pascal  [Select][+][-]
  1.  
  2. This code has been removed, I need to fix it.
  3.  
  4.  

SCREENSHOT
« Last Edit: May 16, 2019, 04:18:18 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

garlar27

  • Hero Member
  • *****
  • Posts: 652
Re: SynEdit for Batch Files
« Reply #9 on: May 16, 2019, 04:03:49 pm »
Didn't read any thing but your code:
Code: Pascal  [Select][+][-]
  1.  
  2. uStr:=TStringList.Create;
  3.    try
  4.       uStr.Assign(SynEdit.Lines);
  5.    finally
  6.       uStr.Free;
  7.    end;
  8.    uStr.SaveToFile(sDlg.Filename);
  9.  
The code is wrong and should give you an Access Violation. It should be like this:
Code: Pascal  [Select][+][-]
  1. uStr:=TStringList.Create;
  2.    try
  3.       uStr.Assign(SynEdit.Lines);
  4.       uStr.SaveToFile(sDlg.Filename);
  5.    finally
  6.       uStr.Free;
  7.    end;
  8.  

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #10 on: May 16, 2019, 04:20:47 pm »
Didn't read any thing but your code:
Code: Pascal  [Select][+][-]
  1.  
  2. uStr:=TStringList.Create;
  3.    try
  4.       uStr.Assign(SynEdit.Lines);
  5.    finally
  6.       uStr.Free;
  7.    end;
  8.    uStr.SaveToFile(sDlg.Filename);
  9.  
The code is wrong and should give you an Access Violation. It should be like this:
Code: Pascal  [Select][+][-]
  1. uStr:=TStringList.Create;
  2.    try
  3.       uStr.Assign(SynEdit.Lines);
  4.       uStr.SaveToFile(sDlg.Filename);
  5.    finally
  6.       uStr.Free;
  7.    end;
  8.  

Actually I realized before you posted that I didn't put the conversion part in.
BTW, that code, does work... I get no errors, it just not the conversion code from ANSi to UTF-8 that is missing

Which I am fixing as we "post"
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #11 on: May 16, 2019, 04:28:04 pm »
So, here is my attempt at converting the SynEdit text from Ansi to UTF-8

I get error on this line...
S:=ConvertEncoding(SynEdit.Lines.Text, 'Ansi', 'UTF-8');

Saying...
Incompatible types: got "AnsiString" expected "TStrings"

CODE THAT DOESN'T WORK
Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.   uStr, S : TStrings;
  4.   i: Integer = 0;
  5.  
  6. uStr:=TStringList.Create;
  7. try
  8.    uStr.Assign(SynEdit.Lines);
  9.      for i:= 0 to SynEdit.Lines.Count - 1 do
  10.         S:=ConvertEncoding(SynEdit.Lines.Text[i], 'Ansi', 'UTF-8');
  11.         uStr.Add(S);
  12.      finally
  13.         uStr.Free;
  14.      end;
  15.  
  16.  
« Last Edit: May 16, 2019, 04:30:20 pm by pixelink »
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #12 on: May 16, 2019, 04:32:18 pm »
Found my error issue.

I had "S" declare as a TString and not a string

CORRECTED VAR
Code: Pascal  [Select][+][-]
  1.  
  2. var
  3.   uStr: TStrings;
  4.   i: Integer = 0;
  5.   S: String;
  6.  
  7.  
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

pixelink

  • Hero Member
  • *****
  • Posts: 1260
Re: SynEdit for Batch Files
« Reply #13 on: May 16, 2019, 04:36:30 pm »
Okay... my attempt to convert code compiled and saved the text exactly as it should, but it still doesn't display the double-line properly in the CMD prompt when I run the *.BAT file.

Now, I don't know where to go from here unless I can know why SynEdit doesn't save the exact format as Notepad does.

Because only notepad written BAT files work.
Can't Type - Forgetful - Had Stroke = Forgive this old man!
LAZ 2.2.0 •  VSSTUDIO(.Net) 2022 • Win10 • 16G RAM • Nvida GForce RTX 2060

korba812

  • Sr. Member
  • ****
  • Posts: 392
Re: SynEdit for Batch Files
« Reply #14 on: May 16, 2019, 04:57:39 pm »
Just one q:
Why or can  the SynEdit be setup to except UTF8 characters by default??
Because the whole LCL is utf8-aware.
btw engkin and jamie were good suggestions, please read:
http://wiki.freepascal.org/Unicode_Support_in_Lazarus
http://wiki.freepascal.org/FPC_Unicode_support

 

TinyPortal © 2005-2018