Recent

Author Topic: Addition to IndustrialStuff Package  (Read 4118 times)

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #45 on: June 17, 2022, 12:27:55 am »
ListBox with just one char per row, where the ScrollBar is wider than the char - it does not look nice. I have also had a horizontal version with ScrollBar - doesn't look good.
OK, it's your component, do whatever you like. Just want to say that it's very annoying for me if I want to look at/edit/delete a character which is in the center of 128 chars and I have to click an large number of times until that small horizontal window is at the right place. If you don't like the scrollbar, another option would be something like the Lazarus character table, i.e. a 2-dimensional selector.

Copy button should remain. No one would like to get his work lost because he accidentally clicked another char from the list.
I see the point, but you could lock selecting another character while editing is active. (In this case, however, another Cancel button must be provided to allow cancel editing without exiting the editor.

As for the OK and Cancel, this would need some code rewrite, because the editor is working "live" on the component. I didn't think about it... Adding a new character adds it direct to the LCDDisplay component, it re-reads the whole character set from the display, and loads the character selector with the new char set.
I would need a local copy of the character defs to work with and implement your chardefs functions again in the editor, or work on a local copy of the TLCDDisplay without a lot of the modifications of the current code (just like the code from my previous upload).
You can use a local copy of the LCDDisplay in your form. Only when OK is pressed the new CharDefs should be passed to the original LCDDisplay in the project.

DotRowCount is easy to implement, but DotColCount...
If you take a look at the functions for converting StringGridData to TDotRows and vice-versa - there is some harcoding inside.
I don't see severe hard-coding here. Replace the "6" by DotRowCount-1, and the bit operations can be handled by a loop along the grid row. Or use the TBits type which largely simplifies bit operations.

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #46 on: June 17, 2022, 06:36:29 pm »
Now I added a basic property editor for TCharDefs and a component editor for TLCDDisplay.

The property editor is in the context menu of the "CharDefs" item in the object inspector (right-click on the property name or on '...'). It has three items: "Edit" (which opens the editor form), "Load from file" (which loads the chardefs from an xml file) and "Save to file" (which saves the current chardefs to an xml file).

The basic integration of the "Edit" command into the object inspector is working. It opens the TLCDDisplayCharDefsEditor form in unit indLCDDisplay_EditorForm. I just put in some basic components to test if its working. The LCDDisplay instance which is edited can be accessed by the property LCDDisplay. The setter method of this property must store the instance in a local variable FLCDDisplay, populate the character selector (which is a combobox here - see below) and set up the rows and cols of the editor grid. It also should save the current chardefs of the LCDDisplay (procedure SaveDefs) so that they can be restored when the user decides to cancel (i.e. not click OK; see OnCloseQuery handler). Please merge your form here, you can delete what I put here. Any change made to the chardefs is reflected immediately in the original LCDDisplay on the edited form.

As for character selection I had the idea that a combobox could do a nice job: you simply type the character to be edited/deleted, and it will be selected automatically without any scrolling. But there is still the option to select the character from the drop-down list.

To avoid having to recompile the ide for testing your changes, I am attaching a simple project which opens the editor form at runtime.



The component editor is in the context menu of the TLCDComponent instance itself. A right-click has the same items as the CharDefs property editor, but I added also an item to enter the text lines here because I thought it would be convenient this way. The text editor is not yet implemented because I still have to investigate whether there is a simple way to "borrow" one from other components. The other three items should work, but unfortunately they don't. It seems that something is missing because their code is not executed ATM. So, more to investigate...



I had to modify the indLCDDisplay unit because the TCharDefs was lacking its adapted Assign method.

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #47 on: June 18, 2022, 01:08:17 pm »
The component editor now executes the commands of the context menu. A double-click opens a memo to enter the LCDDisplay text. What's left is merging your editor code and layout.

bobby100

  • Full Member
  • ***
  • Posts: 100
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #48 on: June 18, 2022, 09:51:05 pm »
Hi wp,

in the editor form, if I select any char in the CharSelector combobox - I can't close the form any more (neither from OK nor from Cancel buttons).
If I delete the text from CharSelector, the form closes as soon as I've deleted the text (if I clicked on OK or on Cancel before that).
Do you experience the same behavior?
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #49 on: June 18, 2022, 10:41:58 pm »
Are you talking of the current char editor used by the property editor of r8313? No problem for me. What are you doing exactly? Your OS? Laz/FPC version?

The property editor needs the TCharDefs.Assign method which was not yet available when we talked the last time. So, you definitely must update to r8313. Should not have this error pattern, though...

Just to make sure: When you downloaded the current version from CCR you must install the package and rebuild the IDE because the property and component editors are linked to the IDE.

If nothing else helps use the test application that I posted yesterday (test_chardefs_editor.zip), go to project options > "Additions and overrides" and add a custom option "-gw3" (without quotes) so that all required units are compiled with debug information and you can step into the LCDDisplay code with the debugger. Find out where the hang occurs.

bobby100

  • Full Member
  • ***
  • Posts: 100
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #50 on: June 19, 2022, 01:00:19 am »
I am using r8313.
Developing by using your test app and rebuilding the IDE every time I have something valuable added to the code.
Problem Nr.1 - I must set cbCharSelector.Text := '' on the clicks or else the btOK and btCancel are not working, either with your TButtonPanel or with my separate buttons.
Problem Nr.2 - in many occasions I can't get data from editing grid (I have exchanged your DrawGrid with a StringGrid). I am storing the edited bits in FTmpDotRows as a workaround.
Problem Nr.3 - CharDefs.Add is storing empty dot matrix. Neither btAdd nor btReplace are working. I see at debugging that I am sending data to Add procedure
Problem Nr.4 - I have used TImageList and BitButtons for editor. In your Test app are the images on BitButtons visible, but not in IDE

EDIT: Lazarus 2.2.2 / FPC 3.2.2 on Win64 - official download from the Lazarus website

EDIT 2: Editor StringGrid editing (setting black and white dots) is working in your test app, but not in the IDE. Adding a TMainMenu isn't working, neither in test app nor in IDE. The Menu is not displayed. The MainMenu is not present in my code upload, it is something I am testing after the upload.
« Last Edit: June 19, 2022, 11:06:40 am by bobby100 »
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #51 on: June 19, 2022, 05:08:41 pm »
I think r8315 should be fairly complete now. If there's still a bug somewhere, let me know.

The reason why the dialog could not be close by clicking the OK or Cancel button is not a fault of the buttons, but the fact that you changed the stringgrid cells in the OnPrepareCanvas event. This event belongs to the grid's drawing code, it is called immediately before the specified cell is painted. If you change the grid cell text here this triggers another painting cycle, and so on. I don't see that a stringgrid must be used here because it just causes double storage of the dot matrix which is already stored in FTmpDotRows. Therefore, I returned to the DrawGrid of my previous code which has less overhead. It reads the bits from FTmpDotRows and paints a cell black when the correspondig bit is set. I also added a MouseDown handler to toggle the bits. (I also replaced the integer helper methods for bit access by methods of the form; I think using the helpers is an unnecessary limitation on the usable FPC version).

I am rather sure that this also fixed the issue that the changes were not applied to the LCD's chardefs. Nevertheless, I had to debug the code for restoring the original chardefs when Cancel was pressed - this did not seem to work. Finally I found that there was code which did not really "copy" a DotRows array, but just the pointer to it, and I had to introduce a function CopyDotRows to create a real, independent copy.

The edAddReplace control was removed because it is needed only for the "Add" case (in the "Restore" case the character can be retrieved from the charselector combobox). When you now select "Add" (which I renamed to "Add as...") an input box opens first to query the name of the new character.

And I used control anchoring to avoid the position calculations in FormActivate.


bobby100

  • Full Member
  • ***
  • Posts: 100
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #52 on: June 19, 2022, 06:33:55 pm »
It is working nice :)
By using DrawGrid, editing the grid by using the keyboard got lost (press space = set/clear). I've added an OnKeyDown in my code:
Code: Pascal  [Select][+][-]
  1. procedure TLCDCharDefsEditor.dgDotMatrixKeyDown(Sender: TObject; var Key: Word;
  2.   Shift: TShiftState);
  3. var
  4.   r, c: integer;
  5. begin
  6.   r := dgDotMatrix.Selection.Top;
  7.   c := dgDotMatrix.Selection.Left;
  8.   if Key = 32 then
  9.   begin
  10.     ToggleDot(c, r);
  11.     dgDotMatrix.InvalidateCell(c, r);
  12.     FModified := true;
  13.   end;
  14. end;
  15.  

Cons of using InputBox instead of TEdit is that in TEdit you can set MaxLength := 1.
InputBox allows more than only one char and the behavior in such case is not defined. It will leave the user with questions. Any suggestions?


EDIT 2: One more change in order to get rid of helpers:
Code: Pascal  [Select][+][-]
  1. procedure TLCDCharDefsEditor.ClearEditorGrid;
  2. var
  3.   i: integer;
  4. begin
  5.   for i := 0 to dgDotMatrix.RowCount - 1 do
  6.     FTmpDotRows[i] := 0;
  7. end;  
  8.  
« Last Edit: June 19, 2022, 06:57:56 pm by bobby100 »
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #53 on: June 19, 2022, 07:01:34 pm »
By using DrawGrid, editing the grid by using the keyboard got lost (press space = set/clear). I've added an OnKeyDown in my code
Thank you. I included it and also added a handler for OnMouseMove.

Cons of using InputBox instead of TEdit is that in TEdit you can set MaxLength := 1.
InputBox allows more than only one char and the behavior in such case is not defined. It will leave the user with questions. Any suggestions?
Which "InputBox"? You mean Combobox? There is a MaxLength also for TCombobox, and it is already active to limit the input to 1 character.

bobby100

  • Full Member
  • ***
  • Posts: 100
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #54 on: June 19, 2022, 07:26:26 pm »
InputBox for 'Add as' button, where you input the character to be added.

In the attachment are two demos for Examples folder.
One is the example that you already had, with minor corrections - Texts corrected from Screen to Display, buttons Save and Open anchored to the radio group over them, hint added for Display ColCount.
The second Example is your CharDefs test app, with a Memo added - to let the user change the text.

EDIT: Please do not forget the code from my 2nd edit in my previous post.
« Last Edit: June 19, 2022, 08:21:16 pm by bobby100 »
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #55 on: June 19, 2022, 11:30:56 pm »
Added the demos and the helper replacement from above.

bobby100

  • Full Member
  • ***
  • Posts: 100
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #56 on: June 20, 2022, 12:21:09 am »
There is an error in the code (Access violation):
Code: Pascal  [Select][+][-]
  1. procedure TLCDCharDefsEditor.ClearEditorGrid;
  2. var
  3.   i: integer;
  4. begin
  5.   for i := 0 to High(FTmpDotRows[i]) do
  6.     FTmpDotRows[i] := 0;
  7. end;
  8.  
Should be:
Code: Pascal  [Select][+][-]
  1. procedure TLCDCharDefsEditor.ClearEditorGrid;
  2. var
  3.   i: integer;
  4. begin
  5.   for i := 0 to High(FTmpDotRows) do
  6.     FTmpDotRows[i] := 0;
  7. end;
  8.  
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #57 on: June 20, 2022, 09:13:38 am »
Grrrh... Fixed.

wp

  • Hero Member
  • *****
  • Posts: 9760
Re: Addition to IndustrialStuff Package
« Reply #58 on: June 22, 2022, 11:22:15 pm »
Is the new stuff in the Industrial package correct now? I'd prepare a new release for OPM then.

bobby100

  • Full Member
  • ***
  • Posts: 100
    • Malzilla
Re: Addition to IndustrialStuff Package
« Reply #59 on: June 23, 2022, 12:22:18 am »
I didn't found any more bugs.
https://gitlab.com/bobby100 - my Lazarus components and units
https://sourceforge.net/u/boban_spasic/profile/ - my open source apps

https://malzilla.org/ - remainder at my previous life as a web security expert

 

TinyPortal © 2005-2018