Recent

Author Topic: What's wrong with my handling of TMemo?  (Read 2221 times)

J-G

  • Hero Member
  • *****
  • Posts: 953
What's wrong with my handling of TMemo?
« on: October 22, 2016, 03:24:08 pm »
I've solved the issue of entering text into a TMemo but have spent two days trying to put that data into a DBrecord.

 
Code: Pascal  [Select][+][-]
  1. [...]
  2. Type
  3.     Event = record
  4.               D      : Date;
  5.               T      : Time;
  6.               Alarm  : TDatetime;
  7.               Desc   : array[1..2] of string[64];
  8.               Loc    : string[64];
  9.               Rep    : byte;
  10.               Mis    : boolean;
  11.               Ack    : boolean;
  12.             end;
  13.  
  14. [...]
  15.  
  16.   Events        : Array[1..30] of Event;
  17.  
  18. [...]
  19.  
  20. procedure Tclock.SaveButtonClick(Sender: TObject);      // EVENT SAVE Button
  21. Var
  22.     Adj, T, Alarm_Time : TDateTime;
  23. begin
  24.   clock.err_mess.visible := false;
  25.   case EvAlarm.Itemindex of
  26.     0 : Adj := 1/96;         // 15 minutes
  27.     1 : Adj := 1/48;         // 30 minutes
  28.     2 : Adj := 1/24;         // 1 hour
  29.     3 : Adj := 1/12;         // 2 hours
  30.   end;
  31.  
  32.   Alarm_Time := EvDate.date+EvTime.time - Adj;
  33.   T := Now;
  34.  
  35.   if Alarm_Time < T then
  36.     begin
  37.       err_Mess.caption := 'Alarm time has already passed - re-enter date-time or cancel';
  38.       clock.err_mess.visible := true;
  39.     end
  40.   else
  41.     begin
  42.       extract_date(EvDate.date+EvTime.time);
  43.       with Diary_Event do
  44.         begin
  45.           D         := Cur_Date;
  46.           T         := Cur_Time;
  47.           Alarm   := Alarm_Time;
  48.           Desc[1] := clock.EvDesc.lines[1];   //  'clock.' added in case it made a difference
  49.           Desc[2] := clock.EvDesc.lines[2];   //                 it  didn't !!
  50.           Loc      := EvWhere.text;
  51.           Rep     := 0;
  52.           Mis      := false;
  53.           Ack      := false;
  54.         end;
  55.       save_Event;
  56.       Clear_EventForm;
  57.     end;
  58. end;
  59.  

EvDesc is a TMemo  -  I don't expect it to handle more than two lines.

All the other fields accept the correct information (Loc is a TEdit - D & T are my own 'types') but on the first run of the data entry form 'Desc[1] and Desc[2] BOTH get whatever I enter into the top line of the TMemo with the first character replaced by '#10'. On subsequent runs they are both empty.

Error handling works as expected and I've worked out how to extract the date and time from TDateEdit  and  TTimeEdit components  -  but I can't see what I can change to make the event description accept what I enter.

FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

holmesshanea

  • Guest
Re: What's wrong with my handling of TMemo?
« Reply #1 on: October 22, 2016, 06:36:12 pm »
zero based?

if you do not expect it to hold more than 2 lines, then shouldn't it be

          Desc[1] := clock.EvDesc.lines[0]; 
          Desc[2] := clock.EvDesc.lines[1];

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: What's wrong with my handling of TMemo?
« Reply #2 on: October 22, 2016, 06:55:19 pm »
DUH!!! :-[

Thanks holmesshanea

Another 'component' under my belt.
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

Eugene Loza

  • Hero Member
  • *****
  • Posts: 663
    • My games in Pascal
Re: What's wrong with my handling of TMemo?
« Reply #3 on: October 22, 2016, 06:56:12 pm »
Also a very good idea is to debug your program with {$R+}{$Q+} (range-checking on). You might get a very weird behaviour while reading/writing beyond-assigned-range memory area.
It'd have pointed you to the line with "Range-check error" message right away.
My FOSS games in FreePascal&CastleGameEngine: https://decoherence.itch.io/ (Sources: https://gitlab.com/EugeneLoza)

J-G

  • Hero Member
  • *****
  • Posts: 953
Re: What's wrong with my handling of TMemo?
« Reply #4 on: October 22, 2016, 07:06:54 pm »
Also a very good idea is to debug your program with {$R+}{$Q+} (range-checking on). You might get a very weird behaviour while reading/writing beyond-assigned-range memory area.
It'd have pointed you to the line with "Range-check error" message right away.
I'll agree that range checking can be useful but in this case .lines[1] and .lines[2] are 'legal' so wouldn't have been picked up.

Oh yes  -  I have checked just in case my addled brain was still playing me up  :)
FPC 3.0.0 - Lazarus 1.6 &
FPC 3.2.2  - Lazarus 2.2.0 
Win 7 Ult 64

 

TinyPortal © 2005-2018