1. Berka Frenfert
  2. PowerBuilder
  3. Wednesday, 3 August 2022 14:33 PM UTC

I remember i did this long ago and it worked (in PB version 10 probably).

I export syntax of an external datawindow then add some data in it and Imported it back into either dll or pbd depending build type.

the "data(" is searched from the exported external dw syntax. then i add at the end of the line new comma separated data. Creating syntax and importing it in library (dll or pbd) is not the problem.

The Problem:

The new last row i added in script at runtime, instead of increasing rowcount, somehow updates any one of the previous rows.
I could not understand this behavior.

But same code when used without creating project and run in Powerbuilder IDE 12.5 the new row is added in previous rows and rowcount increases. It only happens when export and import both are from pbl and app runs in IDE.

 

dwsyntax = LibraryExport(GetCurrentDirectory() + "\btserverdll.pbl", "dwe_list", ExportDataWindow!)	
IF IsNull(dwsyntax) OR TRIM(dwsyntax) = "" THEN
	MSG.Text = "LibraryExport failed."
	RETURN
END IF

TheLine = Pos( dwSyntax, "data(")
TheLineEnd = Pos( dwSyntax, ",)", TheLine)
IF TheLineEnd > TheLine THEN 
	TheLineEnd = Pos( dwSyntax, ",)", TheLine)
	dwSyntax = Replace(dwSyntax, TheLineEnd, 2, + "," +  Trim(NewRow )+ ")") 
ELSE
	IF TheLineEnd <= TheLine THEN 
		TheLineEnd = Pos( dwSyntax, ", )", TheLine)
		dwSyntax = Replace(dwSyntax, TheLineEnd, 3, + "," + Trim(newRow )+ ")") 
	END IF
END IF


rtncode = LibraryImport( GetCurrentDirectory() + "\btserverdll.dll", "dwe_list", ImportDataWindow!, dwsyntax, ErrorBuffer,"dynamic @ runtime")
IF rtncode <> 1 THEN
	///MessageBox("LibraryImport ERROR", ErrorBuffer)
ELSE
	dw_1.DataObject = "dwe_list"
END IF

 

Please note that i carefully checked the export and import is from dll in case of machine code and pbd in pcode. In the above code export is from pbl which i was just testing.

Even after trying all possible combinations i could not get new row added in neither dll nor the pbd.

Is it not possible in PB12.5.

What i am trying to do is that. two application server and client talk to each other on winsock. client sends new row to server side and server keeps list of the rows. Server export the external dw add data in it syntax and import it back. this idea is working only through PB IDE. But when exe runs behavior is different.

I am pretty much sure i have done this through exe long ago. May be forgetting but i need to do it now. Please help because 2 days of effort made my write this request.

 

 

 

 

 

Accepted Answer
Chris Pollach @Appeon Accepted Answer Pending Moderation
  1. Wednesday, 3 August 2022 15:18 PM UTC
  2. PowerBuilder
  3. # Permalink

Hi Berka;

  I do this all the time in my STD Framework. However, the way I do it is ...

  1. Use a PBL only 
  2. Assign the DWO (ie: DS.dataobject = "xxx")
  3. Use the InsertRow() command as required 
  4. Use the LibraryExport() command to save the updated DWO rows back to the PBL in source form

HTH

Regards ... Chris 

 

 

 

Comment
  1. Berka Frenfert
  2. Thursday, 4 August 2022 12:19 PM UTC
Complete syntax that goes to LibraryImport function must be mix of both.

Case:

1- Syntax generated from a template DW (External DW but no data in it)

2- dw_1.dataobject shows that the templates is ok

3- Now data is needed (row can be added and all columns have data)

4- Again Syntax of dw_1 is taken with dw_1.Object.DataWindow.Syntax (the syntax does not include the row )

5- have to use 2nd syntx ( dw_1.Object.DataWindow.Syntax.Data )

6- need to join both after "table(" and before "text(" (tricky part)

Anyway, when dw_1 is external and have now row (template) then syntax will not have "data(" part in it.So need to figure out what is the right way to add "data(" part . So in step 5 we got data syntax which has to fit in between "table(" and "text(".
  1. Helpful
  1. Berka Frenfert
  2. Thursday, 4 August 2022 12:22 PM UTC
UPDATE: previous comment has typing mistake



Anyway, when dw_1 is external and have no row (the template) then syntax will not have "data(" part in it.So need to figure out what is the right way to add "data(" part . So in step 5 we got data syntax which has to fit in between "table(" and "text(".

When both syntax are joined properly then new syntax can be passed to LibraryImport.
  1. Helpful
  1. Berka Frenfert
  2. Thursday, 4 August 2022 12:46 PM UTC
No, Object.DataWindow.Syntax.Data return just the data syntax and if passed to Describe or Modify , wont work. Its just data syntax
  1. Helpful
There are no comments made yet.
Andreas Mykonios Accepted Answer Pending Moderation
  1. Thursday, 4 August 2022 12:37 PM UTC
  2. PowerBuilder
  3. # 1

Hi.

Actually there is no correct place where data should be located. You should only be sure that data() section is not inside another one and starts and closes as expected.

The following example should work:

// ls_syntax: a variable containing the content of a dw syntax
// ls_syntax = string(dw_1.object.datawindow.syntax)\
// -------------------------------------------------------------
// ls_data: a variable containing data from dw
// ls_data = string(dw_1.object.datawindow.syntax.data)

string ls_errmsg

// Just put at the end of ls_syntax the content of ls_data.
Dw_2.Create(ls_syntax + "~r~n" + ls_data, ls_errmsg)

// After that command the datawindow should be rendered with it's contents...

Andreas.

Comment
  1. Berka Frenfert
  2. Thursday, 4 August 2022 14:19 PM UTC
That is nice thing :)
  1. Helpful
There are no comments made yet.
Berka Frenfert Accepted Answer Pending Moderation
  1. Friday, 5 August 2022 11:23 AM UTC
  2. PowerBuilder
  3. # 2

 

I wanted to save data in external dw at runtime.

Created a Aside.pbl and created dwe_list (the external datawindow) in it.

Deployed project and got PBD along with exe file.

Discarded the exe file and picked the generated Aside.pbd

Created real project and also included the Aside.pbd in Libraries List. (having in mind that i will not generate pbd again for Aside.pbd when deploy project)

Wrote script and used Aside.pbd in both functions (Library Import/Export)

Deployed real project (Pcode) but unchecked the PBD checkbox for Aside.pbd

Generated Exe file and executed it to test  if new row is saved in the Aside.pbd

But it did not work. same idea applied to machine code and used Aside.dll instead but data was not saved into Aside.dll.

I did it long ago but have no idea how. Anyway this time i renamed  Aside.pbl to Aside.pbd. used it in project Library List (even rename to dll or txt and include it in library list it will work). Changed script to use correct Aside.pbd/dll/txt whatever. deployed project again in either pcode or machine code but did not check the check box for DLL/PBD.

This is how it worked for me. I checked with txt extension :) (just for fun)

Extension can be anything.

And it worked.

Basically Chris gave the correct idea. PowerBuilder checks internal file format and it must be PBL. I stop the idea of pushing data into real PBD or DLL file format.

 

With help of ideas from Chris and Andreas i finally got rid of this problem.

Thank you for sharing and caring.

True regards,

Berka

Comment
  1. Chris Pollach @Appeon
  2. Friday, 5 August 2022 13:15 PM UTC
That's great news Berka! Thanks for the feedback. ;-)
  1. Helpful
There are no comments made yet.
  • Page :
  • 1


There are no replies made for this question yet.
However, you are not allowed to reply to this question.