Setting TcxSpinEdit property to column when building TcxGrid at runtime - delphi

I'm working on someone else's code where they're building a TcxGrid without going through the visual editor. I will be exporting that grid to excel so I need to set the column type to TcxSpinEdit (contents are all numbers).
How can I set the property? I tried with PropertyClass and PropertyClassName but none of them work (I still get the "number as text" warning in excel).
This is the relevant part:
var
Stolpec: TcxGridDBColumn;
[...]
if CheckBoxStevilkoMultiTime.Checked then
begin
Stolpec := cxGrid1DBTableView3.CreateColumn;
Stolpec.DataBinding.FieldName := 'STVLK_INI_C';
Stolpec.Width := larghCol;
Stolpec.FooterAlignmentHorz := taRightJustify;
Stolpec.GroupSummaryAlignment := taRightJustify;
Stolpec.Name := 'cxGrid1DBTableView3' + Colonna.DataBinding.FieldName;
TcxGridDBTableSummaryItem(cxGrid1DBTableView3.DataController.Summary.DefaultGroupSummaryItems[5]).Column := Stolpec;
TcxGridDBTableSummaryItem(cxGrid1DBTableView3.DataController.Summary.DefaultGroupSummaryItems[5]).Position := posIndx;
Stolpec.Caption := 'Stevilko';
Stolpec.Options.Editing := False;
end;

uses
cxSpinEdit;
...
Stolpec.PropertiesClass := TcxSpinEditProperties;
TcxSpinEditProperties(Stolpec.Properties).MaxValue:= 10;
...

Related

Delphi FMX Programmatically using TListview

Good day
I am trying to build an application which requires me to display multiple images in groups with selectable sizes.  The images consist of a bitmap and a text field.  My idea is to put the image groups in a TListview (Which I hope can display horizontally) and then add these listview groups into a TFlowlayout to manage the screen layout.
However, I simply do not get it right to create a TListview item programmatically to display the image.  I have tried to create a TListItemImage as well as simply adding a TListViewItem but neither worked in that I could see anything on the screen.
I am including my test code (Note it pulls images from a folder for testing).  The commented out sections will probably indicate some of the experiments that I tried.
I will probably also struggle to add the TListviews to the TFlowlayout.  Some advice will be much appreciated.  The idea is that the application will run on both Android mobile as well as desktops.
function TForm1.BuildGrpObj(GroupSize, CurrPicIdx: integer): boolean;
var
aPicObj : TListViewitem;
k: Integer;
aPicObjImg: TListItemImage;
// aPicObjImg: TListViewItem;
FName: string;
begin
for k := 0 to GroupSize-1 do
begin
aPicObj := Listview1.Items.Add;
aPicObj.Text := 'Picture: ' + inttostr(CurrPicIdx + k);
aPicObjImg := TListItemImage.Create(aPicObj);
// aPicObjImg := Listview1.Items.Add;
FName := LList[CurrPicIdx + k];
// aPicObjImg.Bitmap := TBitmap.Create;
aPicObjImg.Bitmap.LoadFromFile(FName);
aPicObjImg.Align := TListItemAlign.Center;
aPicObjImg.VertAlign := TListItemAlign.Center;
aPicObjImg.PlaceOffset.X := 0;
aPicObjImg.PlaceOffset.Y := 0;
aPicObjImg.Width := 40;
aPicObjImg.Height := 40;
aPicObjImg.invalidate;
end;
result := true;
end;

Delphi Firemonkey creating TExpanders and TLabels at runtime

Using Rad Studio 10.3
I am creating TExpanders at runtime based on a FireDAC query. However i am running into an issue setting the Parent of the label to the expander i have just created.
I am using the following to create the components
procedure TfrmMain.FormCreate(Sender: TObject);
var
i: integer;
begin
// Populate previous saved conversions stringgrid
FDQuery1.SQL.Clear;
FDQuery1.Close;
FDQuery1.SQL.Add('SELECT convert from conversions');
FDQuery1.Open;
i := 1;
while not FDQuery1.Eof do
begin
// Create Expanders here to display database query to user
exp := TExpander.Create(Self);
exp.Parent := layoutDBDisplay;
exp.Align := TAlignLayout.Top;
exp.Name := 'dbExp' + i.ToString;
exp.Height := 100;
exp.TextSettings.Font.Size := 14;
exp.TextSettings.Font.Style := [TFontStyle.fsBold];
// Create TLabel inside of above expander
lab := TLabel.Create(Self);
lab.Parent := TExpander;
lab.Align := TAlignLayout.Top;
lab.Name := 'dbResLabel' + i.ToString;
inc(i);
FDQuery1.Next;
end;
FDQuery1.Close;
end;
The issue is lies in this line
lab.Parent := expName;
Obviously the above won't compile because of the following
[dcc32 Error] frmConverter.pas(266): E2010 Incompatible types: 'TFmxObject' and 'class of TExpander'
Is there a simple solution to this?
Your line
lab.Parent := TExpander;
should be
lab.Parent := Exp;

Delphi Markup Label throws "Control 'MDLabel1' has no parent window."

Searching for a Delphi label component with basic format/markup support I came across Delphi Markup Label (MDLabel). As a bonus it supports links. Unfortunately I can't get it working. The component is provided as a single MD_Label.pas file. I've created a component package for it and installed it. I can now select it from the components list, but adding it to a form throws an error:
Control 'MDLabel1' has no parent window."
I traced it down to the call CreateWnd and found some topics for similar problems, but still wasn't able to solve this. Did I do something wrong or is this something that needs to be adjusted because the initial code was written for Delphi 2007 and I'm using XE?
The component is to large to post the whole source code here, but you can download it from the link above. Here's the creation part:
constructor TMDLabel.Create(AOwner: TComponent);
begin
FInitialized := False; // required for runtime creation of MDLabel
inherited;
ControlStyle := [csOpaque, csCaptureMouse, csClickEvents, csSetCaption];
FLinkFontNormal := TFont.Create;
FLinkFontNormal.Assign(Font);
FLinkFontNormal.Color := clBlue;
FLinkFontNormal.Style := [];
FLinkFontHover := TFont.Create;
FLinkFontHover.Assign(Font);
FLinkFontHover.Color := clRed;
FLinkFontHover.Style := [fsUnderline];
Width := 100;
Height := 13;
Cursor := crArrow;
TabStop := False;
DoubleBuffered := True;
FTextHeight := 0;
FAutoSizeWidth := True;
FAutoSizeHeight := True;
FTextAlignment := taLeftJustify;
FCompressSpaces := False;
FTabWidth := 8;
FParsingText := False;
FBuildingLines := False;
FRebuildLines := False;
FMaxWidth := 0;
FLinkFontNormal.OnChange := DoFontChange;
FLinkFontHover.OnChange := DoFontChange;
FOnLinkClicked := nil;
FOnPaintBackground := nil;
FOnHeightChanged := nil;
FOnWidthChanged := nil;
FLines := TList.Create;
FWords := TList.Create;
FLinkRCs := TList.Create;
FMouseDownMove := False;
FMouseWasDown := False;
FMouseDownIndex := - 1;
FInitialized := True;
end;
procedure TMDLabel.CreateWnd;
begin
inherited CreateWnd;
{$IFNDEF UNICODE}
if (inherited Caption <> '') and (FCaptionUTF8 = '') then CaptionUTF8 := inherited Caption;
{$ENDIF}
end;
Full source: http://pastebin.com/sxYvpqTy
As a side note: If you feel that there's a better component that supports formating text within labels, please feel free to share as a comment (TJvHTLabel and TJvMarkupLabel are not good).
This error is a very common one for component authors who don't understand how the VCL works internally.
The fact that the error occurs while dropping the component on the Form at design-time means that the component's constructor is doing something it should not be. One of the operations requires the component's Handle to have an allocated HWND, but that is not possible at the time of the error because the component's Parent property has not been assigned yet, or the Parent.Handle does not have an allocated HWND of its own. The Parent is not assigned until after the constructor exits.
So, you need to debug the code and find the offending constructor code that relies on the component's Handle property, and move it out of the constructor. Depending on which code it is, it either belongs in Loaded() or CreateWnd(), or even SetParent(), or it may even need to be disabled completely at design-time (sometimes run-time code should not be executed at design-time or during DFM streaming at all).

change color of listviewitem text in delphi

i'm trying to change the text color within my listviewitem for a text object. I have multiple text objects in the listviewitem. I'm using the below code
Litem := ListView1.Items.Add;
Litem.Data['ytde'] := currtostrf(ytde,ffCurrency,2);
Litem.Data['ytdbe'] := currtostrf(ytdbe,ffCurrency,2);
Litem.Data['ytdetotal'] := currtostrf(ytdetotal,ffCurrency,2);
Litem.Objects.TextObject.TextColor := TAlphaColorRec.Green
The error when debugging says inaccessible object yet i have no problem changing the color when i do the below
LItemheader.Purpose := TListItemPurpose.Header;
Litemheader.Objects.TextObject.TextColor := TAlphaColorRec.blue;
any ideas?
Found the answer :
TListItemText(Litem.Objects.FindDrawable('ytde')).TextColor := TAlphaColorRec.Red;

Make an installer with text that is formatted (Partially Bold) in Inno Setup?

Anyone saw GOG.com game installer? How to make welcome text string like there including Path and Need Size in a single Caption? Where part of is bolded.
Here are examples of how changes String line breaking after modifying install path
You can use a TRichEditViewer setting the RFTText property and the UseRichEdit to True.
Try this sample
procedure CreateCustomPages;
var
Page : TWizardPage;
rtfHelpText : TRichEditViewer;
s: string;
begin
Page := CreateCustomPage(wpWelcome, 'Custom wizard page controls', 'Bold Demo');
Page.Surface.Align:=alCLient;
s:='{\rtf1\ansi\ansicpg1252\deff0\deflang13322{\fonttbl{\f0\fnil\fcharset0 Tahoma;}}'+
'\viewkind4\uc1\pard\f0\fs16 This is a normal text, \b and this is a bold text\b0\par}';
rtfHelpText := TRichEditViewer.Create(Page);
rtfHelpText.Parent := Page.Surface;
rtfHelpText.Left := 0;
rtfHelpText.Top := 0;
rtfHelpText.Width := Page.SurfaceWidth;
rtfHelpText.Height := Page.SurfaceHeight;
rtfHelpText.Scrollbars := ssVertical;
rtfHelpText.ReadOnly := True;
rtfHelpText.UseRichEdit := True;
rtfHelpText.RTFText := s;
end;
procedure InitializeWizard();
begin
CreateCustomPages();
end;

Resources