Re: [Lazarus] Base64 broken in json?

2015-06-02 Thread Michael Van Canneyt



On Mon, 1 Jun 2015, Leonardo M. Ramé wrote:


El 30/05/15 a las 13:29, silvioprog escibió:

On Sat, May 30, 2015 at 12:14 PM, Leonardo M. Ramé l.r...@griensu.com
mailto:l.r...@griensu.com wrote:


[Window Title]
project1

[Content]
{ var1 : bGVvbmFyZG8= } - leonardo

[OK]

But after take a look at your code, it seems better to use as:

myString := '{ var1: ' + StringToJsonString(Base64EncodedString) + ' }'

Because function StringToJsonString will encode string in a
JSON-escape string.



Hi Silvio, can you try encoding the attached file, then output using both 
methods?.


I tested your file with the following program:

program jsonb;

uses sysutils, classes, fpjson, jsonparser, base64;

Var
  O : TJSONObject;
  F : TFileStream;
  S : TStringStream;

begin
  S:=Nil;
  O:=Nil;
  try
F:=TFileStream.Create(ParamStr(1),fmOpenRead);
S:=TStringStream.Create('');
With TBase64EncodingStream.Create(S) do
  try
CopyFrom(F,0);
Flush;
O:=TJSONObject.Create(['file',S.DataString]);
  finally
Free;
  end;
FreeAndNil(S);
S:=TStringStream.Create(O.Get('file'));
S.Position:=0;
FreeAndNil(F);
F:=TFileStream.Create(ChangeFileExt(paramstr(1),'.base64'),fmCreate);
F.CopyFrom(S,0);
  finally
O.Free;
F.Free;
S.Free;
  end;
end.

cadwal: ./jsonb plantilla-original.ott
cadwal: base64 -d plantilla-original.base64  b.ott
cadwal: ls *.ott -l
-rw-rw-r-- 1 michael michael 41956 Jun  2 09:16 b.ott
-rw-rw-r-- 1 michael michael 41956 Jun  2 09:05 plantilla-original.ott
cadwal: cmp b.ott plantilla-original.ott

cmp reports all is well.

Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] StringGrid.loadFromCSVFile question

2015-06-02 Thread Koenraad Lelong

Op 01-06-15 om 15:30 schreef Bart:

On 6/1/15, Koenraad Lelong lazar...@de-brouwerij.be wrote:


A few months ago I made an application that uses
StringGrid.LoadFromCSVFile. This worked.
Now, on a PC with a newer linux-OS, and a newer Lazarus/FPC, I try to
work further on that application but now the application from the
original sources crashes. It seems it can no longer automatically append
lines to a stringgrid. Error : index out of range Cell[Col=0, Row=x].
When I manually append lines (= in the IDE) the application can load
some more lines, but crashes when the grid-lines are all used.



Please attach a sample program and sample .csv to demonstrate the problem.
Keep it as simple as possibe (1 grid, 1 button should suffice).

Bart


I think I better open a bug-report.
I found what's the problem : I use two fixed rows.
When I tried to make that sample program I was surprised the minimal 
version worked, but then I added a second fixed row, and then it crashed 
also.


Koenraad.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Base64 broken in json?

2015-06-02 Thread Leonardo M. Ramé



El 02/06/15 a las 09:21, Michael Van Canneyt escibió:



On Tue, 2 Jun 2015, Leonardo M. Ramé wrote:

You cannot copypaste that, because there may be escaped characters in 
it.

If you are doing that, you are doing it wrong.



Hmm. That's the problem, then.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Dropdown in stringgrid ?

2015-06-02 Thread Jesus Reyes A.
En Tue, 02 Jun 2015 06:01:05 -0500, Koenraad Lelong  
lazar...@de-brouwerij.be escribió:



Hi,

I'm trying to make a universal importer.
I have a database I want to populate/modify with data from a csv-file.  
The column order of the csv-file cannot be imposed. So I have to have a  
way to say which column of the csv-file is which field in the database.


I have a commercial application that has something like a stringgrid but  
the first row has dropdown's with possible field-names. I was trying to  
mimic this, more or less, but had issues.


Is this possible someway ? Any hints ?

Koenraad



In the grid such combobox is called a picklist.

1. Select the grid
2. In the Object Inspector select the columns property and click the ...  
button.

3. Add some custom columns
4. Select the column where you wish to add a pick list
5. In the Object Inspector change the ButtonStyle to cbsPickList
6. In the Object Inspector select the PickList property and click the  
... button.

7. Add all options you want to this list.
8. make sure the grid is editable.

Jesus Reyes A.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Base64 broken in json?

2015-06-02 Thread Michael Van Canneyt



On Tue, 2 Jun 2015, Leonardo M. Ramé wrote:




El 02/06/15 a las 04:20, Michael Van Canneyt escibió:



On Mon, 1 Jun 2015, Leonardo M. Ramé wrote:


El 30/05/15 a las 13:29, silvioprog escibió:

On Sat, May 30, 2015 at 12:14 PM, Leonardo M. Ramé l.r...@griensu.com
mailto:l.r...@griensu.com wrote:


[Window Title]
project1

[Content]
{ var1 : bGVvbmFyZG8= } - leonardo

[OK]

But after take a look at your code, it seems better to use as:

myString := '{ var1: ' + StringToJsonString(Base64EncodedString) +
' }'

Because function StringToJsonString will encode string in a
JSON-escape string.



Hi Silvio, can you try encoding the attached file, then output using
both methods?.


I tested your file with the following program:

program jsonb;

uses sysutils, classes, fpjson, jsonparser, base64;

Var
   O : TJSONObject;
   F : TFileStream;
   S : TStringStream;

begin
   S:=Nil;
   O:=Nil;
   try
 F:=TFileStream.Create(ParamStr(1),fmOpenRead);
 S:=TStringStream.Create('');
 With TBase64EncodingStream.Create(S) do
   try
 CopyFrom(F,0);
 Flush;
 O:=TJSONObject.Create(['file',S.DataString]);
   finally
 Free;
   end;
 FreeAndNil(S);
 S:=TStringStream.Create(O.Get('file'));
 S.Position:=0;
 FreeAndNil(F);
 F:=TFileStream.Create(ChangeFileExt(paramstr(1),'.base64'),fmCreate);
 F.CopyFrom(S,0);
   finally
 O.Free;
 F.Free;
 S.Free;
   end;
end.

cadwal: ./jsonb plantilla-original.ott
cadwal: base64 -d plantilla-original.base64  b.ott
cadwal: ls *.ott -l
-rw-rw-r-- 1 michael michael 41956 Jun  2 09:16 b.ott
-rw-rw-r-- 1 michael michael 41956 Jun  2 09:05 plantilla-original.ott
cadwal: cmp b.ott plantilla-original.ott

cmp reports all is well.

Michael.




Thanks Michael, what if you save the json object to file using:

with TStringList.Create do
begin
 Text := O.AsJson;
 SaveToFile('test.json');
end;

Then copy the content of the file variable, and save as test.base64?


You cannot copypaste that, because there may be escaped characters in it.
If you are doing that, you are doing it wrong.

Michael.--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] StringGrid.loadFromCSVFile question

2015-06-02 Thread Bart
On 6/2/15, Koenraad Lelong lazar...@de-brouwerij.be wrote:

 I think I better open a bug-report.
 I found what's the problem : I use two fixed rows.
 When I tried to make that sample program I was surprised the minimal
 version worked, but then I added a second fixed row, and then it crashed
 also.


OK, but also there attach sample project + offending .csv file so we
can reproduce.

Bart

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] StringGrid.loadFromCSVFile question

2015-06-02 Thread Koenraad Lelong

Op 02-06-15 om 12:30 schreef Bart:

On 6/2/15, Koenraad Lelong lazar...@de-brouwerij.be wrote:


I think I better open a bug-report.
I found what's the problem : I use two fixed rows.
When I tried to make that sample program I was surprised the minimal
version worked, but then I added a second fixed row, and then it crashed
also.



OK, but also there attach sample project + offending .csv file so we
can reproduce.

Bart


Bug ID = 0028230

Koenraad


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] Dropdown in stringgrid ?

2015-06-02 Thread Koenraad Lelong

Hi,

I'm trying to make a universal importer.
I have a database I want to populate/modify with data from a csv-file. 
The column order of the csv-file cannot be imposed. So I have to have a 
way to say which column of the csv-file is which field in the database.


I have a commercial application that has something like a stringgrid but 
the first row has dropdown's with possible field-names. I was trying to 
mimic this, more or less, but had issues.


Is this possible someway ? Any hints ?

Koenraad

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] Base64 broken in json?

2015-06-02 Thread Leonardo M. Ramé



El 02/06/15 a las 04:20, Michael Van Canneyt escibió:



On Mon, 1 Jun 2015, Leonardo M. Ramé wrote:


El 30/05/15 a las 13:29, silvioprog escibió:

On Sat, May 30, 2015 at 12:14 PM, Leonardo M. Ramé l.r...@griensu.com
mailto:l.r...@griensu.com wrote:


[Window Title]
project1

[Content]
{ var1 : bGVvbmFyZG8= } - leonardo

[OK]

But after take a look at your code, it seems better to use as:

myString := '{ var1: ' + StringToJsonString(Base64EncodedString) +
' }'

Because function StringToJsonString will encode string in a
JSON-escape string.



Hi Silvio, can you try encoding the attached file, then output using
both methods?.


I tested your file with the following program:

program jsonb;

uses sysutils, classes, fpjson, jsonparser, base64;

Var
   O : TJSONObject;
   F : TFileStream;
   S : TStringStream;

begin
   S:=Nil;
   O:=Nil;
   try
 F:=TFileStream.Create(ParamStr(1),fmOpenRead);
 S:=TStringStream.Create('');
 With TBase64EncodingStream.Create(S) do
   try
 CopyFrom(F,0);
 Flush;
 O:=TJSONObject.Create(['file',S.DataString]);
   finally
 Free;
   end;
 FreeAndNil(S);
 S:=TStringStream.Create(O.Get('file'));
 S.Position:=0;
 FreeAndNil(F);
 F:=TFileStream.Create(ChangeFileExt(paramstr(1),'.base64'),fmCreate);
 F.CopyFrom(S,0);
   finally
 O.Free;
 F.Free;
 S.Free;
   end;
end.

cadwal: ./jsonb plantilla-original.ott
cadwal: base64 -d plantilla-original.base64  b.ott
cadwal: ls *.ott -l
-rw-rw-r-- 1 michael michael 41956 Jun  2 09:16 b.ott
-rw-rw-r-- 1 michael michael 41956 Jun  2 09:05 plantilla-original.ott
cadwal: cmp b.ott plantilla-original.ott

cmp reports all is well.

Michael.




Thanks Michael, what if you save the json object to file using:

with TStringList.Create do
begin
  Text := O.AsJson;
  SaveToFile('test.json');
end;

Then copy the content of the file variable, and save as test.base64? 
and try base64 -d test.base64, this is what I tried to do and got errors 
decoding.


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


[Lazarus] TProcess not mirroring terminal

2015-06-02 Thread JuuS
Hi All,

I'm using Lazarus 1.4 with Kubuntu 14.04

I've written a small GUI frontend for the rsync command. I assemble
rsync command line switches and source and destination thru the TProcess
paramlist and everything has been exactly mirrored by my program and
when the exact same command is run through a terminal, it has worked
perfectly for everything I want to do with rsync...

...until today.

For the first time my output and the output from the same command line
run in terminal work differently.

Run it through terminal and the command is accepted, however running it
through TProcess and rsync complains! The two outputs are listed below,
the parameters passed are exactly the same.


Anyone have an idea why this is so???



TERMINAL OUTPUT:
juus@JuuSKub:~$ rsync -n -vshtplgiE --stats --modify-window=1 --progress
/home/juus/Documents/** /media/juus/Lin1TB/BKactive
skipping directory CodeBlocks
skipping directory IntelliJ
skipping directory qt
f+ hackjs5.html
f+ hackjs7.html
f+ hackjs8.html

Number of files: 3 (reg: 3)
Number of created files: 3 (reg: 3)
Number of deleted files: 0
Number of regular files transferred: 3



OUTPUT FROM MY PROGRAM
rsync: link_stat /home/juus/Documents/** failed: No such file or
directory (2)

Number of files: 0
Number of created files: 0
Number of deleted files: 0
Number of regular files transferred: 0

:: Parameters passed to RSYNC:
-n
-vshtplgiE
--stats
--modify-window=1
--progress
/home/juus/Documents/**
/media/juus/Lin1TB/BKactive


thanks,

Julius

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TProcess not mirroring terminal

2015-06-02 Thread JuuS


On 06/02/2015 03:42 PM, Marc Santhoff wrote:
 On Di, 2015-06-02 at 14:21 +0200, JuuS wrote:
 
 Anyone have an idea why this is so???
 
 Maybe the difference is that your TProcess is reading only stdout, not
 stderr. Dunno if there is a switch in TProcess, if not you'd need to
 redirect stderr to stdout (which is shell dependant, 21 for sh,  for
 csh, IIRC).
 

Thanks for reply Marc, but Michael had it absolutely right.

I changed my TProcess to run /bin/sh instead of rsync, added -c as first
param, then the entire rsync command as second param.

It works Great!

Thanks for your answers guys.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TProcess not mirroring terminal

2015-06-02 Thread JuuS


On 06/02/2015 04:20 PM, Mark Morgan Lloyd wrote:
 JuuS wrote:
 
 Thanks for the answer. wildcards do work fine when I make exclude and
 include params, but then those are interpreted by rsync as simple
 patterns to match. So you are saying that in the case of the actual
 source folder param the shell must be involved and passing it through
 TProcess params won't work?
 
 Note also this behaviour from Bash:

Interesting insight, thanks. I've learned a lot about shell today... :)

 
 $ echo fpc*
 fpc fpc.tar fpcbuild-2.2.4.tar.gz fpcbuild-2.4.0.tar.gz
 $ echo fred*
 fred*
 
 So * is expanded if files match, but is passed through unchanged if not.
 This means that if your program isn't expanding * based on what's in a
 directory, there are some cases where it will be behaving the same as
 the shell :-)
 

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TProcess not mirroring terminal

2015-06-02 Thread Mark Morgan Lloyd

JuuS wrote:


Thanks for the answer. wildcards do work fine when I make exclude and
include params, but then those are interpreted by rsync as simple
patterns to match. So you are saying that in the case of the actual
source folder param the shell must be involved and passing it through
TProcess params won't work?


Note also this behaviour from Bash:

$ echo fpc*
fpc fpc.tar fpcbuild-2.2.4.tar.gz fpcbuild-2.4.0.tar.gz
$ echo fred*
fred*

So * is expanded if files match, but is passed through unchanged if not. 
This means that if your program isn't expanding * based on what's in a 
directory, there are some cases where it will be behaving the same as 
the shell :-)


--
Mark Morgan Lloyd
markMLl .AT. telemetry.co .DOT. uk

[Opinions above are the author's, not those of his employers or colleagues]

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TProcess not mirroring terminal

2015-06-02 Thread Michael Van Canneyt



On Tue, 2 Jun 2015, JuuS wrote:


Hi All,

I'm using Lazarus 1.4 with Kubuntu 14.04

I've written a small GUI frontend for the rsync command. I assemble
rsync command line switches and source and destination thru the TProcess
paramlist and everything has been exactly mirrored by my program and
when the exact same command is run through a terminal, it has worked
perfectly for everything I want to do with rsync...

...until today.

For the first time my output and the output from the same command line
run in terminal work differently.

Run it through terminal and the command is accepted, however running it
through TProcess and rsync complains! The two outputs are listed below,
the parameters passed are exactly the same.


Anyone have an idea why this is so???



As a wild guess: You cannot specify * or ** (or any wildcard), 
because that must be escaped using the shell.


Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TProcess not mirroring terminal

2015-06-02 Thread Marc Santhoff
On Di, 2015-06-02 at 14:21 +0200, JuuS wrote:

 Anyone have an idea why this is so???
 
 
 
 TERMINAL OUTPUT:
 juus@JuuSKub:~$ rsync -n -vshtplgiE --stats --modify-window=1 --progress
 /home/juus/Documents/** /media/juus/Lin1TB/BKactive
 skipping directory CodeBlocks
 skipping directory IntelliJ
 skipping directory qt
 f+ hackjs5.html
 f+ hackjs7.html
 f+ hackjs8.html
 
 Number of files: 3 (reg: 3)
 Number of created files: 3 (reg: 3)
 Number of deleted files: 0
 Number of regular files transferred: 3
 
 
 
 OUTPUT FROM MY PROGRAM
 rsync: link_stat /home/juus/Documents/** failed: No such file or
 directory (2)
 
 Number of files: 0
 Number of created files: 0
 Number of deleted files: 0
 Number of regular files transferred: 0

Maybe the difference is that your TProcess is reading only stdout, not
stderr. Dunno if there is a switch in TProcess, if not you'd need to
redirect stderr to stdout (which is shell dependant, 21 for sh,  for
csh, IIRC).

-- 
Marc Santhoff m.santh...@web.de


--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] StringGrid.loadFromCSVFile question

2015-06-02 Thread Bart
On 6/2/15, Koenraad Lelong lazar...@de-brouwerij.be wrote:

 Bug ID = 0028230

OK.

Bart

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TProcess not mirroring terminal

2015-06-02 Thread JuuS
 
 You can simply execute the shell and use its -c option to pass the rsync
 command with all options.

Ok, thanks Michael. I will look into it.

 
 Michael.
 
 -- 
 ___
 Lazarus mailing list
 Lazarus@lists.lazarus.freepascal.org
 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TProcess not mirroring terminal

2015-06-02 Thread Michael Van Canneyt



On Tue, 2 Jun 2015, JuuS wrote:




On 06/02/2015 02:31 PM, Michael Van Canneyt wrote:



On Tue, 2 Jun 2015, JuuS wrote:


Hi All,

I'm using Lazarus 1.4 with Kubuntu 14.04

I've written a small GUI frontend for the rsync command. I assemble
rsync command line switches and source and destination thru the TProcess
paramlist and everything has been exactly mirrored by my program and
when the exact same command is run through a terminal, it has worked
perfectly for everything I want to do with rsync...

...until today.

For the first time my output and the output from the same command line
run in terminal work differently.

Run it through terminal and the command is accepted, however running it
through TProcess and rsync complains! The two outputs are listed below,
the parameters passed are exactly the same.


Anyone have an idea why this is so???



As a wild guess: You cannot specify * or ** (or any wildcard), because
that must be escaped using the shell.


Thanks for the answer. wildcards do work fine when I make exclude and
include params, but then those are interpreted by rsync as simple
patterns to match. So you are saying that in the case of the actual
source folder param the shell must be involved and passing it through
TProcess params won't work?


If you type the command on the command-line, then the shell will have 
interpreted them.
rsync will not see them.



I can live with this, but it would be nice for it work. Any way to
tickle the shell in some way through TProcess??


You can simply execute the shell and use its -c option to pass the rsync 
command with all options.

Michael.

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus


Re: [Lazarus] TProcess not mirroring terminal

2015-06-02 Thread JuuS


On 06/02/2015 02:31 PM, Michael Van Canneyt wrote:
 
 
 On Tue, 2 Jun 2015, JuuS wrote:
 
 Hi All,

 I'm using Lazarus 1.4 with Kubuntu 14.04

 I've written a small GUI frontend for the rsync command. I assemble
 rsync command line switches and source and destination thru the TProcess
 paramlist and everything has been exactly mirrored by my program and
 when the exact same command is run through a terminal, it has worked
 perfectly for everything I want to do with rsync...

 ...until today.

 For the first time my output and the output from the same command line
 run in terminal work differently.

 Run it through terminal and the command is accepted, however running it
 through TProcess and rsync complains! The two outputs are listed below,
 the parameters passed are exactly the same.


 Anyone have an idea why this is so???

 
 As a wild guess: You cannot specify * or ** (or any wildcard), because
 that must be escaped using the shell.

Thanks for the answer. wildcards do work fine when I make exclude and
include params, but then those are interpreted by rsync as simple
patterns to match. So you are saying that in the case of the actual
source folder param the shell must be involved and passing it through
TProcess params won't work?

I can live with this, but it would be nice for it work. Any way to
tickle the shell in some way through TProcess??


 Michael.
 
 -- 
 ___
 Lazarus mailing list
 Lazarus@lists.lazarus.freepascal.org
 http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus

--
___
Lazarus mailing list
Lazarus@lists.lazarus.freepascal.org
http://lists.lazarus.freepascal.org/mailman/listinfo/lazarus