Lazarus Style Help about form - lazarus

I need to create an about entry for a Lazarus project. I would like it to be a multi page affair like the about one in the Lazarus IDE but I cannot find any information about doing so.

The one in the Lazarus about box and what I also use for many of my projects is a TTabControl. What I find particularly useful is to use this in conjunction with a TRichMemo and then have different RTF files for each tab that are then compiled into the program as resources.
For example, for one project I have four tabs. I use the caption for each tab as part of the name of the resource for that tab. My resource file for it looks like this:
ABOUTBOX_INSTRUCTIONS RCDATA "Resources/Instructions.rtf" LANGUAGE 0,0
ABOUTBOX_LICENSE RCDATA "Resources/License.rtf" LANGUAGE 0,0
ABOUTBOX_CHANGELOG RCDATA "Resources/Changelog.rtf" LANGUAGE 0,0
ABOUTBOX_CREDITS RCDATA "Resources/Credits.rtf" LANGUAGE 0,0
Switching tabs then becomes relatively easy to do:
//---------------------------------------------------------------------------
// tabAboutTabs OnChange event handler. Load the appropriate resource into
// the RichMemo box.
//
procedure TAboutBox.tabAboutTabsChange(Sender: TObject);
var
ResourceStream: TResourceStream;
begin
// Each tab's caption becomes part of the resource name for the RTF file loaded.
ResourceStream := TResourceStream.Create(HInstance, 'ABOUTBOX_' + UpperCase(tabAboutTabs.Tabs[tabAboutTabs.TabIndex]), RT_RCDATA);
richAboutText.LoadRichText(ResourceStream);
ResourceStream.Free;
end;
//---------------------------------------------------------------------------
This gives you the ability to have a multi-tab help form with nicely formatted text you can generate with a word processor that is embedded right inside your executable.

Related

Dynamically insert number on Delphi app's icon

I'm on Delphi 10.4.
I'm looking for a way to dynamically insert a number on the app's icon on the taskbar, so the user can know about how many tasks the apps has done so far. This would be dynamically, as soon as the app does a new task, it will increase the icon's number.
Something like the image below.
Is this possible ?
I don't have any code to post here because i don't have any idea how to do this.
You might not be aware of the TTaskbar taskbar-configuration component and its OverlayIcon property.
Example:
with a very straightforward implementation:
procedure TForm1.btnInfoClick(Sender: TObject);
var
io: TIcon;
begin
io := TIcon.Create;
try
io.Handle := LoadIcon(0, IDI_INFORMATION);
Taskbar1.OverlayIcon := io
finally
io.Free;
end;
end;
In your case, you can either create icons 1.png, 2.png, ... non-programmatically and use those, or you can create icons programmatically (create a CreateOverlayIcon(ANumber: Integer): TIcon function).
I should warn you, however, that the TTaskbar component used to be (very) buggy. Therefore I would not use that one; instead, I would use the ITaskbarList3::SetOverlayIcon API directly.
In any case, my suggestion is to split your problem into two parts:
Create overlay icons.
Use the Windows 7 taskbar overlay icon feature to display these on top of your original icon.

How would you render soft returns in a Richedit control?

In an application that displays a richedit control I would like to be able to visually distinguish soft returns (produced with SHIFT ENTER) from hard returns (produced with ENTER).
I already use the JVCL richedit and don't want to switch at that point.
How would you proceed to do that?
Microsoft Word may be an inspiration source, they display a ↵ sign for soft returns and a ¶ sign for hard returns at the end of each line.
I am just looking for hints, good ideas how you would tackle this project. I am not asking anybody to do my work, of course. :-)
I already use the JVCL richedit and don't want to switch at that point.
The JVCL rich edit control wraps the Windows rich edit control. The Windows rich edit control won't show whitespace the way you desire. It has no functionality to do so. If you want the control to display such symbols you'd need to paint them yourself and I doubt that can be done in a very effective and slick way.
It sounds like you are displaying code because you mention syntax highlighting. In which case a rich edit control is the wrong choice. You should use a control designed for displaying and/or editing code.
Although not a direct answer to your question, there is a possible solution to the problem you mentioned of needing to use both Richedit and Syntax highlighting in one control and that is the use of SynEdit.
SynEdit include some non-visual components that allow exporting syntax formatted text, one of those components is TSynExporterRTF.
Suppose you have a section of code which is in plain text inside your richedit and you want to syntax highlight that portion, you could select and copy that text to a TSynEdit and then export it to a TSynExporterRTF which will now contain syntax formatted text (assuming a highlighter has been defined correctly). Then you can simply write the data to a TMemoryStream and replace the selected richedit text with the now syntax formatted code.
To do this you can try something like this:
procedure SyntaxFormatRichEditText(RichEdit: TRichEdit; SynHighlighter: TSynCustomHighlighter);
var
SynEdit: TSynEdit;
SynExporterRTF: TSynExporterRTF;
MS: TMemoryStream;
begin
SynEdit := TSynEdit.Create(nil);
try
SynEdit.Highlighter := SynHighlighter;
SynEdit.Lines.Text := RichEdit.SelText;
SynExporterRTF := TSynExporterRTF.Create(nil);
try
SynExporterRTF.Highlighter := SynHighlighter;
MS := TMemoryStream.Create;
try
SynExporterRTF.ExportAll(SynEdit.Lines);
SynExporterRTF.SaveToStream(MS);
MS.Seek(0, soBeginning);
RichEdit.SetSelTextBuf(MS.Memory);
RichEdit.SetFocus;
finally
MS.Free;
end;
finally
SynExporterRTF.Free;
end;
finally
SynEdit.Free;
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
SyntaxFormatRichEditText(RichEdit1, SynPasSyn1);
end;
If anything though, as others have suggested the requirements you need are likely out of scope as to what the Richedit controls can offer.

VB 6 and Right to Left layout windows application

I have an old windows application with it's Ocxs. I want to localize it's OCX to arabic. no problem on changing labels and strings.
but I can't change layout to Right to left.
I find some resources about using Mirroring in windows. but the provided samples don't help me. Link1 & Link2
I'm not a VB fan and don't have enough experience.
Is there any clear and tested approach for VB to mirroring UI?
From Platform SDK 2001
Complex Scripts in Edit Controls
A complex script is a language whose printed form is not laid out in a simple way. For example, a complex script may allow bi-directional rendering, contextual shaping of glyphs, or combining characters. The standard edit controls have been extended to support multilingual text and complex scripts. This includes not only input and display, but also correct cursor movement over character clusters (in Thai and Devanagari script, for example).
A well-written application will receive this support automatically, without modification. Again, you should consider adding support for right-to-left reading order and right alignment. In this case, toggle the extended style flags of the edit control window to control these attributes, as shown in the following example:
// ID_EDITCONTROL is the control ID in the resource file.
HANDLE hWndEdit = GetDlgItem(hDlg, ID_EDITCONTROL);
LONG lAlign = GetWindowLong(hWndEdit, GWL_EXSTYLE) ;
// To toggle alignment
lAlign ^= WS_EX_RIGHT ;
// To toggle reading order
lAlign ^= WS_EX_RTLREADING ;
After setting the lAlign value, enable the new display by setting the extended style of the edit control window as follows:
// This assumes your edit control is in a dialog box. If not,
// get the edit control handle from another source.
SetWindowLong(hWndEdit, GWL_EXSTYLE, lAlign);
InvalidateRect(hWndEdit, NULL, FALSE);
Windows 2000/XP: The standard edit control supports a context menu that allows the user to toggle the reading order and insert/display Unicode bi-directional control characters.

Replacing form controls in vb6

We have an in house button control, and quite frankly it sucks. I'd like to replace it but I don't want to go onto every form in our project and delete/add a new control. It seems to me that if I design a new button that has all the same properties as the old one then I ought to be able to give it the same name as the old one and just replace all the reference lines in the vbp files to point to the new control.
Has anyone tried this (better yet have you heard of a tool that will do it for you) and if so what 'gotchas' should I be on the look out for?
Thanks!
The *.vbp files are one place you'll need to change. There are also references to the used control libraries in the files containing GUIs -- that's form (*.frm), control (*.ctl), and property page (*.pag) files. These files are in a plain text format and you can see the references at the top. They look like this:
Object = "{831FDD16-0C5C-11D2-A9FC-0000F8754DA1}#2.0#0"; "mscomctl.ocx"
Those refs will need to be added or updated in all relevant files if the new control is a compiled OCX. If it's in the same project I don't think it needs any reference there, and if it's in a different project in the same project group I'm not sure. Save a test form with the new control to see.
Note that you don't have to keep the same control class name. Inside the *.frm/ctl/pag files, instances of individual controls on them are represented by a simple format like this:
Begin VB.CommandButton Command2
Caption = "Cancel"
Height = 375
Left = 2460
TabIndex = 1
Top = 2400
Width = 1455
End
The syntax of the first line there is "Begin LibraryOrProjectName.ClassName NameOfThisInstance". So, provided the offending control's name is distinctive it should be easy to search & replace references to it both in the BASIC source and in the GUI layouts. You might want a plain text editor that can perform search and replace across multiple files (Notepad++ is one).
Some control properties are stored like this:
Picture = "frmMain.frx":292F
These correspond to the *.frx, *.ctx, and *.pgx files, which contain binary data for the values of certain control properties. I don't think these files should need altering or cause any problems. They don't appear to contain control names.
Use a full compile (Ctrl+F5) to be sure no problems linger in parts of the source afterward.
Never tried it. Good luck.
There is only one tip to be added to the accepted answer.
If you need to replace any generic VB control with 3rd party or custom ActiveX control you must replace the:
BeginProperty Font
with
BeginProperty Font {0BE35203-8F91-11CE-9DE3-00AA004BB851}
Omiting to do so results with run-time error 713 when trying to edit/open the form.
If there is no BeginProperty statement in the block then control uses default font and this replacement is not needed.
An additional scenario to look for is if the classes in the OCX are referenced directly in code.
In other words, if the control class was ABCButton then you need to look for ABCButton in all .BAS and .CLS files as well, and make appropriate changes.

Import Images from File delphi

I'm familiar with delphi scripting so I basically need a strong direction to start from. I've done importing images from files in other languages and it has been quite trivial, but I can find little documentation about this for delphi.
I need to be able to register a control event on a button that will open up a "choose folder/file" dialouge, and then import an image into an object that I can append to a List of some sort.
Anyone have any documentation on this?
Although your question is rather broad and "delphi scripting" sounds interesting here is an example that might get you started:
Project: Let the user select an image and display this image
This form contains a TButton, a TOpenPictureDialog and a simple TImage for displaying one image (sorry, no list of pictures in this example).
Part 1 ("register a control event on a button"):
Attach an OnClick event handler to the button by double clicking the button in the form designer. If your button's Name is btnOpenPicture then the auto-generated handler will have the name btnOpenPictureClick (see the following code). The code in this handler will be executed when the user clicks the button.
procedure TForm1.btnOpenPictureClick(Sender: TObject);
begin
if OpenPictureDialog1.Execute(Self.Handle) then
Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);
end;
Part 2 ("'choose folder/file' dialouge") is represented by OpenPictureDialog1.Execute which opens a dialog where the user can choose a picture. The Execute command waits until the user closes the dialog and returns True if the user chose not to cancel the dialog but rather chose an image file (the filename is stored in OpenPictureDialog1.FileName).
Part 3 ("import an image into an object") would then be Image1.Picture.LoadFromFile which instructs the TImage component to load and display the file the user chose.
I cannot immediately name a component included in Delphi which could be used easily as a list for displaying images visually (that's your "append to a List of some sort"). I only know some third-party components which are not available for free, thus not good for quick experimenting.
Maybe this can be a base for asking more specific questions (as already encouraged by the commentators of your question). I already have one: "Is there a VCL component I could use for displaying a list of images?"
There are lots of articles and tutorials on how to do this. Code for loading images can be found in this Stackoverflow question; to complete your problem, you need a TButton and probably a TOpenPictureDialog.

Resources