With a customer I'm stuck developing for this very old version (2.1) of ExpressQuantumGrid by DevExpress. In Delphi 4. I can't find any documentation about it.
Basically I just need to create a bunch of TdxDBGridMaskColumn and "insert" them into the grid (TdxDBGrid) at runtime. From the code completion pop-up I can't figure out how.
Thanks!
We have an old app that uses Delphi 5 and DevExpress v3, the code might not be identical but should get you started.
A function that can create a column of any type (TdxDBDateColumn for example):
function CreateColumn(const aField: string; aColClass: TdxDBTreeListColumnClass): TdxDBTreeListColumn;
var
begin
Result := dxGrid.CreateColumn(aColClass);
Result.Name := dxGrid.Name + aField;
TdxDBGridColumn(Result).DisableFilter := True;
TdxDBGridColumn(Result).DisableGrouping := True;
TdxDBGridColumn(Result).Alignment := taRightJustify;
TdxDBGridColumn(Result).FieldName := aField;
TdxDBGridColumn(Result).Caption := aField;
TdxDBGridColumn(Result).Width := 70;
end;
Then you can call this function like so:
NewColumn := CreateColumn('Username', TdxDBGridColumn);
Related
I have too many Forms and I have a procedure that should be running on all form when created
procedure TDM.SetupForm(Max, DisableResize,
DisableMove: Boolean; FormWidth: Integer = 0; FormHeight: Integer = 0);
var
Form: TForm;
begin
Form := ??? // How to find the what form is running this procedure?
Form.AutoScroll := True;
if Max then
begin
Form.Width := Screen.WorkAreaWidth;
Form.Height := Screen.WorkAreaHeight;
Form.Top := 0;
Form.Left := 0;
end
else
begin
if FormWidth > 0 then
Form.Width := FormWidth;
if FormHeight > 0 then
Form.Height := FormHeight;
Form.Position := poScreenCenter;
Form.Align := alCustom;
end;
if DisableResize then
DeleteMenu(GetSystemMenu(Form.Handle, False), SC_SIZE, MF_BYCOMMAND);
if DisableMove then
DeleteMenu(GetSystemMenu(Form.Handle, False), SC_MOVE, MF_BYCOMMAND);
Form.BorderIcons := [biSystemMenu];
if Form.Height > Screen.WorkAreaHeight then
Form.Height := Screen.WorkAreaHeight;
if Form.Width > Screen.WorkAreaWidth then
Form.Width := Screen.WorkAreaWidth;
Form.ShowHint := True;
Form.OnClose := CloseFormAction;
end;
I call this Procedure on FormCreate event
How can I find what form is calling this procedure and use it inside same procedure without passing it as parameter?
I call this procedure on FormCreate event
It seems to me you don't actually need to know the "Last Created Form", but rather which form is currently being created, which you want to call this code for. If that is the case, simply add a TForm parameter to this procedure instead of declaring a variable and trying to obtain it from elsewhere...
procedure TDM.SetupForm(Form: TForm; Max, DisableResize,
DisableMove: Boolean; FormWidth: Integer = 0; FormHeight: Integer = 0);
begin
...Use the `Form` parameter...
Then you would pass Self into this whenever you call it from FormCreate...
DM.SetupForm(Self, ....
Ultimately, this sort of thing is best accomplished by creating a base form first, and then inheriting all the rest of your forms from this base. Such code would be implemented in the base form's constructor, and then you wouldn't have to explicitly call it from each and every form you wish to apply it to. However, it seems you already have many forms written and this would require modifying all of your existing code to consider the base form. Such design should be done from the beginning of development.
I must also note that putting UI code of such nature into a data module is not the right practice. A data module's purpose is to be disconnected from the UI. That's why it's not actually a visible form, but a non-visual-component-only solution. It's best to put such code in independent units for that purpose, such as MyApp.UICommon.pas.
I want to align a text to center and I have no idea on how to achieve it.
Here is my code:
try
MsWord := GetActiveOleObject('Word.Application');
except
try
MsWord := CreateOleObject('Word.Application');
MsWord.Visible := True;
except
Exception.Create('Error');
end;
end;
MSWord.Documents.Add;
MSWord.Selection.Font.Size := 22;
MSWord.Selection.Font.Bold := true;
MSWord.Selection.TypeText(#13#10);
MSWord.Selection.TypeText('I want this to be center-aligned');
...
MSWord.ActiveDocument.SaveAs('C:\doc2.doc');
Please help.
Thanks
This works for me:
procedure TForm1.Button1Click(Sender: TObject);
var
MSWord : OleVariant;
begin
try
MsWord := GetActiveOleObject('Word.Application');
except
try
MsWord := CreateOleObject('Word.Application');
MsWord.Visible := True;
except
Exception.Create('Error');
end;
end;
MSWord.Documents.Add;
MSWord.Selection.Font.Size := 22;
MSWord.Selection.Font.Bold := true;
MSWord.Selection.TypeText(#13#10);
MSWord.Selection.TypeText('I want this to be center-aligned');
MSWord.Selection.ParagraphFormat.Alignment := wdAlignParagraphCenter;
MSWord.ActiveDocument.SaveAs('C:\doc2.doc');
end;
Btw, the way to find the answer yourself is to go into Word, start recording a macro, perform the action, stop recording then edit the macro to see what code Word generates. Converting that to Delphi is usually fairly trivial if you're using late binding (accessing Word from Delphi via an OleVariant) but can be a bit long winded if you're using early binding, because early binding requires all parameters to be specified, whereas late binding lets you leave most of them out.
In this code I am trying to add TadvTabSet in runtime I have got an error:
Access violation at address 00DC0FB0 in the module Projet4.exe. read of address 00000258.
The code causing it:
with tset.AdvTabs.Add do
begin
tag:=strtoint(en_vente.Text);
name:='tab'+inttostr(tset.AdvTabs.count);
caption:=enom.Text;
end;
I can't see anything that would be a problem. Can someone help figure out why?
This is an example that I generally use, except for this answer, the code that creates the components on the TAdvOfficePage was removed. Don't forget to add any events for the components you add to the TAdvOfficePage.
procedure TForm1.AddOfficePage;
begin
AdvOfficePage := TAdvOfficePage.Create(AdvOfficePager1);
AdvOfficePage.Parent := AdvOfficePager1;
AdvOfficePage.AdvOfficePager := AdvOfficePager1;
AdvOfficePager1.AddAdvPage(AdvOfficePage);
AdvOfficePager1.ActivePage := AdvOfficePage;
{Add components next}
end;
Whoops... I now see that you wanted to add a TTabCollectionItem to an TAdvTabSet.
procedure TForm1.AddTabCollectionItem;
{ Add a TTabCollectionItem to TAdvTabSet. }
var
i: Integer;
begin
for i := 0 to 9 do
begin
ATabCollectionItem := AdvTabSet1.AdvTabs.Add;
ATabCollectionItem.Caption := 'Tab Collection Item ' + IntToStr(i);
end;
end;
For example with the TPageControl you need to create a tab first and then add to it...
maybe is the same here...
myTab:= TTabSheet.Create(YourPageControlAsOwner);
myTab.name:= ...
myTab.caption:=...
//and the asociated events you need after create
myTab.onClick:= YourOwnMethod...
I using Delphi BDS 2006 and have a DevExpress cxGridDBColumn with properties set to DateEdit and was wondering whether it is possible to add a checkbox to the displayed date time picker popup?
I am not sure that I understand what you wish to achieve. Anyway, it is impossible without creating a custom cxEditor which supports this look&feel and desired functionality.
Here is a quick hack which should help you implement this feature. However, you should handle the checkBox yourself. I have done this for the standalone editor, however, the same approach will work with the inplace editor:
procedure TForm1.cxDateEdit1PropertiesPopup(Sender: TObject);
var
AEdit: TcxDateEdit;
ACalendar: TcxPopupCalendar;
ACheckBox: TcxCheckBox;
begin
AEdit := TcxDateEdit(Sender);
if AEdit.Tag <> 1 then
begin
AEdit.Tag := 1;
ACalendar := TcxPopupCalendar(AEdit.Properties.PopupControl);
ACheckBox := TcxCheckBox.Create(Self);
ACheckBox.Parent := ACalendar.Parent;
ACheckBox.Align := alBottom;
ACheckBox.Transparent := True;
ACalendar.Parent.Height := ACalendar.Parent.Height + ACheckBox.Height;
end;
end;
I'm using Delphi 5, and we have a method to dynamically create certain controls based on the contents of a database table (we create TButtons mostly) and take action when those are clicked. This allows us to add simple controls to a form without having to recompile the application.
I was wondering if it was possible to set a component's property based on a property name contained in a string so we could set further options.
Pseudo-code:
Comp := TButton.Create(Self);
// Something like this:
Comp.GetProperty('Left').AsInteger := 100;
// Or this:
Comp.SetProperty('Left', 100);
Is this possible at all?
You have to use the Run-Time Type Information features of Delphi to do this:
This blog describes exactly what you are trying to do: Run-Time Type Information In Delphi - Can It Do Anything For You?
Basically you have to get the property information, using GetPropInfo and then use SetOrdProp to set the value.
uses TypInfo;
var
PropInfo: PPropInfo;
begin
PropInfo := GetPropInfo(Comp.ClassInfo, 'Left');
if Assigned(PropInfo) then
SetOrdProp(Comp, PropInfo, 100);
end;
This is not as concise as your pseudo-code, but it still does the job. Also it gets more complicated with other stuff, like array properties.
From one of my working units (in Delphi 7 though)
var
c : TComponent;
for i := 0 to pgcProjectEdits.Pages[iPage].ControlCount - 1 do
begin
c := pgcProjectEdits.Pages[iPage].Controls[i];
if c is TWinControl
then begin
if IsPublishedProp(c,'color')
then
SetPropValue(c,'color',clr);
if IsPublishedProp(c,'readonly')
then
SetPropValue(c,'readonly', bReadOnly );
...
end;
...
You have to include TypInfo in the uses statement.
Don't know if this works under Delphi 5.
Just as an added example. Here is how to set sub-properties, I'm setting the Margins on this Button component:
uses TypInfo;
...
procedure TForm1.Button1Click(Sender: TObject);
begin
var PropInfo := GetPropInfo(Button1.ClassInfo, 'Margins');
if Assigned(PropInfo) then
begin
var Margins := TMargins.Create(self);
try
Margins.Left := 100;
Margins.Top := 100;
Margins.Right := 100;
Margins.Bottom := 100;
SetObjectProp(Button1, PropInfo, Margins);
finally
Margins.Free;
end;
end;
end;
This works on Delphi 10.3 Rio and later due to the inline variables.