Recent

Author Topic: KOL-CE - compact applications for WinCE  (Read 132448 times)

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
KOL-CE - compact applications for WinCE
« Reply #75 on: April 21, 2008, 06:16:11 pm »
Can you provide complete code example which triggers this error?

Chainfire

  • New Member
  • *
  • Posts: 28
KOL-CE - compact applications for WinCE
« Reply #76 on: April 21, 2008, 07:06:42 pm »
Trying to whip something up for you :) It'll be a couple of hours.

EDIT:

I'm having a freakishly hard time reproducing the issue outside the project... Of course I'm still going to continue trying, but here is another piece of info you may find interested / could be a hint:

Code: [Select]

var
  List: TStrList;
begin
  List := RegEnum(...)^; // returns PStrList
  try
    if List.Count > 0 then
      ....
  finally
    List.Free; <---- AV HERE
  end;
end;


I changed this to:

Code: [Select]

begin
  with RegEnum(...)^ do
  try
    if Count > 0 then
      ....
  finally
    Free; <---- WORKS ?!
  end;
end;


I tried to do this several different ways, and this was the only one that worked, completely removing the List variable.

Unfortunately, I still have PList's in 5 other places that are having the same issue, for which I have not yet found a way to free them correctly (ie, without throwing the same exception as quoted in my previous post).

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
KOL-CE - compact applications for WinCE
« Reply #77 on: April 21, 2008, 09:39:37 pm »
I just noticed that you declared var as:
Code: [Select]
var
  List: TStrList;

But it is totally wrong. It explains why you get the errors.
You should use PStrList varaible.
Code: [Select]
with RegEnum(...)^ do
is correct.

Chainfire

  • New Member
  • *
  • Posts: 28
KOL-CE - compact applications for WinCE
« Reply #78 on: April 21, 2008, 09:47:32 pm »
Ok, I'm not following that.

In KOL.pas is declared:

PStrList = ^TStrList

so:

var List: TStrList;
List := NewStrList^;

why exactly is this not correct ?

I use the above all over the place, and it usually works.

EDIT: Ok, I adjusted it everywhere and indeed the problem disappears. Thanks a bunch! As for what I said ^^^, is that because you are using 'poor' objects ?

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
KOL-CE - compact applications for WinCE
« Reply #79 on: April 22, 2008, 11:36:56 am »
Yes. It is because 'poor' objects in KOL library. Class instances are always pointers, while objects can be static instances TXXX or dynamic instances PXXX (pointers).

In this code you copy contents of dynamic instance of StrList to static instance in variable List:

var List: TStrList;
List := NewStrList^;

Then you are trying to release static instance and get the error.

All KOL objects are designed to be dynamic and you must work with pointers only...

P.S. 'poor' objects are just records with methods. So use record rules for them.

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Sometimes date2Strfmt('dd-MM-yyyy',date) gives empty str
« Reply #80 on: April 24, 2008, 09:37:27 am »
Sometimes, on the WM6-pda,

Date2Strfmt('dd-MM-yyyy',date)  

returns an empty string.

I traced into KOL.pas and found  function SystemDate2Str;

Here an empty string is returned if GetMem fails or if GetDateFormat fails. Could this ever happen?

On subsequent calls, the result remained empty. The rest of the program just kept working. After a restart, the result was ok, so the problem is not easy to reproduce.

Any ideas?

tia!
John

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Events lost when transferring sources to other PC
« Reply #81 on: April 24, 2008, 04:37:51 pm »
This afternoon I freshly reinstalled a new daily snapshot.

After that I copied a complete KOL-projectdir from my dev machine to this new machine.  Compiles fine on the dev-machine, both to WinCE and to Win32 targets.

- Open Project, ok.
- Build All, ok
- Run : no events fired.

Paths are all the same. All events have dissapeared from the object-inspector and are not fired at runtime either (e.g. OnClick-event on a button). Doubleclicking the button does not create event. Doubleclicking in object-inspector does not create new event or find existing event in unit.

If I drop a NEW TKolbutton on the form, I can define its onclick-event (partly) the usual way: doublleclick the TKolbutton creates an event in the codeeditor, but it does NOT appear in the OI.

Even if I select the still existing event in the dropdownlist in the object-inspector, the editbox in the OI stays empty...

If I create a new KOL-project, everything works fine. So I suspect there is something in the files that I copied from the other machine. [EDIT] Oooops, disregard this... the event appeared once in th OI, but after adding another TKolbutton, everything was gane again... [/EDIT]

If I copy a projectsource from Laz 0.9.25/fpc 2.2.0 to Laz 0.9.25/fpc 2.2.1, should I make precautions to some files? Or setup some parameters in the IDE?

tia!
John

[EDIT2]
Weird... a second time CleanUp+BuildAll did the job. It now works as expected. Still curious what could have been the problem!
[/EDIT2]

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
RE: Events lost when transferring sources to other PC
« Reply #82 on: April 25, 2008, 11:33:40 am »
If you are using Lazarus 0.9.25 or later you need to rebuld Lazarus with DisableFakeMethods defined before installing MCK package.

To do that:

   1. Run Lazarus.
   2. Choose Tools > Configure "Build Lazarus"... menu item.
   3. Choose Clean Up + Build all on Quick Build Options page.
   4. Open Advanced Build Options page and add -dDisableFakeMethods into Options input field.
   5. Click Build button to rebuild Lazarus.

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
Re: Sometimes date2Strfmt('dd-MM-yyyy',date) gives empty str
« Reply #83 on: April 25, 2008, 11:57:08 am »
Quote from: "JohnvdWaeter"
Sometimes, on the WM6-pda,

Date2Strfmt('dd-MM-yyyy',date)  

returns an empty string.

I traced into KOL.pas and found  function SystemDate2Str;

Here an empty string is returned if GetMem fails or if GetDateFormat fails. Could this ever happen?

On subsequent calls, the result remained empty. The rest of the program just kept working. After a restart, the result was ok, so the problem is not easy to reproduce.

Any ideas?


It seems that GetDateFormat fails. Are you sure that date value is correct?
You need to debug this problem by yourself and find what exactly fail.

Chainfire

  • New Member
  • *
  • Posts: 28
KOL-CE - compact applications for WinCE
« Reply #84 on: April 28, 2008, 11:38:56 pm »
Quote from: "yury_sidorov"
Yes. It is because 'poor' objects in KOL library. Class instances are always pointers, while objects can be static instances TXXX or dynamic instances PXXX (pointers).

In this code you copy contents of dynamic instance of StrList to static instance in variable List:

var List: TStrList;
List := NewStrList^;

Then you are trying to release static instance and get the error.

All KOL objects are designed to be dynamic and you must work with pointers only...

P.S. 'poor' objects are just records with methods. So use record rules for them.


Wow, I can't believe I've been developing in Object Pascal for 8 years now and didn't know that. That's very useful information, and it being just a record with methods explains a lot. Also opens up for some C++ header translations I thought before were impossible.

Thanks again for your hard work, your assistance and the information!

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Attaching a TKolbutton.Onclick dynamically?
« Reply #85 on: April 29, 2008, 03:44:32 pm »
Hi Yury,

In my CE-appl I dynamically create forms the user has to fill in. I have a TKolPanel on which there are an editbox and 2 buttons.
The editbox accepts numeric input only.
The Buttons have a plus and a minus as caption.

If a user presses
  • , the value should be increased.

If the user presses [-], the value in the editbox should be decreased. Something like a spinedit.

This TKolpanel is created at runtime, maybe 1 instance, maybe 10 instances on a form, used and freed.

When creating the buttons and the editbox, I want to attach the buttons Onclick to a generic eventhandler. In Delphi/VCL I would search Sender.Parent (which is the panel) for an editbox and adjust its textvalue. How to write something like that using KOL?

Is there a way to do something like:
Code: [Select]

for n:=1 to (sender as tkolbutton).parent.Childcount-1 do
 if  (sender as tkolbutton).parent.Children[n] is TKolEditbox
  then ...do something...

??

tia!
John

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: Sometimes date2Strfmt('dd-MM-yyyy',date) gives empty str
« Reply #86 on: April 29, 2008, 04:59:59 pm »
[/Quote]
It seems that GetDateFormat fails. Are you sure that date value is correct?
You need to debug this problem by yourself and find what exactly fail.[/quote]

You won't believe it... it only happens on sundays!!

date2Strfmt('dd-MM-yyyy',date) returns an empty string and GetLastError (in KOL.PAS, function SystemDate2Str) says 87, which is ERROR_INVALID_PARAMETER, but only when date returns a date that is a sunday.... ???

Beats me..... any suggestions appreciated!

kind regards
John

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: Sometimes date2Strfmt('dd-MM-yyyy',date) gives empty str
« Reply #87 on: April 29, 2008, 09:40:48 pm »
Function DayOfWeek should return 0..6 as stated in the comment below the function declaration. The systemtime-structure also needs 0..6.

But the formula in the function returns 1..7

If I remove the +1 at the end of the formula, all seems to work ok, but I'm not sure if this could possibly break other code?

tia!
John

yuriy_sydorov

  • Full Member
  • ***
  • Posts: 158
RE: Re: Sometimes date2Strfmt(
« Reply #88 on: April 29, 2008, 10:56:59 pm »
Indeed, DayOfWeek was wrong. It is fixed now. Thanks.

Since all KOL standard controls implemented in single TControl object, you need to use Tag property to identify controls. Set Tag of edit boxes to some value and the code will be:

Code: [Select]
for n:=1 to sender.parent.Childcount-1 do
 if  sender.parent.Children[n].Tag = SomeValue
  then ...do something...


P.S. You can use real updown control to create spinedit:
http://www.kolnmck.ru/files/kolce/comp/kolce_updown.7z

JohnvdWaeter

  • Full Member
  • ***
  • Posts: 185
    • http://www.jvdw.nl
Re: RE: Re: Sometimes date2Strfmt(
« Reply #89 on: May 01, 2008, 02:12:34 pm »
Hi Yury,

Thanks.

Other things:

1. Is it possible to implement and publish OnEnter and OnLeave for TKolDateTimePicker? I'd like to change color when receiving or losing focus.

2. Does exist any documentation (in English) on how to use TKolFrame?

thanks again,
John

 

TinyPortal © 2005-2018