Frequently Asked Component Specific Questions
Options |
Display all FAQ items |
Displaying items 706 to 720 of 888, page 48 of 60
<< previous next >>



Programmatically adding page, toolbar and button to the ribbon
Following code snippet illustrates how you can add a new page with a new toolbar and a new button via code to the Office 2007 ribbon control. To test this, drop a TAdvToolBarPager on the form and add following code:
var AdvPage: TAdvPage; AdvToolBar: TAdvToolBar; AdvGlowButton: TAdvGlowButton; begin AdvPage := TAdvPage.Create(self); AdvPage.Caption := 'New page'; AdvPage.AdvToolBarPager := AdvToolBarPager1; AdvToolBarPager1.ActivePageIndex := AdvToolBarPager1.AdvPageCount - 1; AdvToolBar := TAdvToolBar.Create(self); AdvToolBar.Parent := AdvPage; AdvToolBar.Caption := 'New toolbar'; AdvGlowButton := TAdvGlowButton.Create(Self); AdvGlowButton.Parent := AdvToolBar; AdvGlowButton.Caption := 'New Button'; AdvGlowButton.ShowCaption := true; end;



Registering components and methods in workflow scripting system
The Workflow Studio manual describes how to register new components, methods, classes and properties to a scripter component by using methods like DefineClass, DefineProp, etc.. However, Workflow Studio creates a new scripter component instance for each script block that is used in a workflow instance. Due to that, you must use OnGlobalScripterCreate event to make sure you initialize all scripter components in the system. The following steps show how to do that. The OnGlobalScripterCreate is a global variable of type TNotifyEvent declared in Wf.Script.pas unit. First of all, you need to set that global variable to a method in your application:
{PrepareScripter is a method in any of your existing and instantiated classes} OnGlobalScripterCreate := PrepareScripter;
Procedure TMyDataModule.PrepareScripter(Sender: Tobject); begin With TwfCustomScripter(Sender) do begin AddComponent(Form1); end; end;



Updating Chart at runtime
When updating the chart component at runtime it is important to "tell" the chart to update itself.
Whenever you change properties, or add/remove points the chart will not be updated.
This is because the chart will be repainted over and over again every time you change a property.
This would cause a slow performance.
To update the chart at runtime, after you change properties, you must use the BeginUpdate / EndUpdate methods.
Sample: Updating a series of points at runtime
procedure TForm1.Button1Click(Sender: TObject); begin AdvChartView1.BeginUpdate; with AdvChartView1.Panes[0].Series[0] do begin Points[0].SingleValue := 100; Points[1].SingleValue := 50; Points[2].SingleValue := 20; Points[3].SingleValue := 30; Points[4].SingleValue := 150; Points[5].SingleValue := 160; end; AdvChartView1.EndUpdate; end;



Programmatically slide a panel in and out
To slide in or slide out a panel, following code can be used:
AdvToolPanelTab.RollOut(AdvToolPanel1); // slide the panel in view AdvToolPanelTab.RollIn(AdvToolPanel1); // slide the panel out of view



Programmatically docking and undocking panels
To programmatically change the state of a TAdvToolPanel to floating or docked, the methods ManualFloat and ManualDock can be used. To check the docking / floating state of a panel, the property TAdvToolPanel.Floating can be used. The code snippet below toggles between floating and docked state:
begin if not AdvtoolPanel1.Floating then AdvtoolPanel1.ManualFloat(rect(20,20,200,200)) else AdvtoolPanel1.ManualDock(advtoolpaneltab1); end;



Using MacroRecorder on Windows Vista/Windows 7 or newer machines
Microsoft decided that the API used for functionality of the TMacroRecorder component is a security risk on Windows Vista. Therefore, Microsoft disabled the API used for recording & playing mouse & keyboard events back in Windows Vista by default. In order to have this functionality enabled for your applications it is required:
- Digitally sign your executable. See http://stackoverflow.com/questions/252226/signing-a-windows-exe-file
- Run your executable as adminstrator or elevate rights to administrator
- Deploy your application under \program folders



Avoid the dialog "Shutdown application..." during updates
You can turn off that this dialog is displayed just before the application restarts by adding in the control .INF file following setting:
[application] silentrestart=1



Delphi can't find definition for TFlxFormat when using TAdvGridExcelIO
This type is defined in the unit tmsUFlxFormats. Add the unit tmsUFlxFormats to the uses clause and the problem should be solved.



Saving/Loading compile code for scripter projects
When using standard Scripter component with a single script, you just need to call SaveCodeToFile and LoadCodeFromFile methods of scripter component to handle compiled code. When it comes to multi-script project using the Scripter Studio Pro engine, you must write extra code and save compiled code of all units (scripts). It's the same for loading: you must load compile code of all units. This is a pseudo-code example for saving compiled code:
for c := 0 to IDEEngine1.Files.Count - 1 do begin if not IDEEngine1.Files[i].Script.Compiled then IDEEngine1.Files[i].Script.Compile; AUnitName := IDEEngine1.Files[i].Script.ScriptInfo.UnitName; IDEEngine1.Files[o].Script.SaveCodeToFile(ABasePath + AUnitName + '.code'); end;
with IDEScripter1 do begin {By setting the LibOptions properties below, you just need to load the script code for the main unit} LibOptions.UseScriptFiles := true; LibOptions.SearchPath.Add(SomeSearchPath); LibOptions.CompiledFileExt := '.code'; Scripts.Clear; {Load main unit only - the other units will be loaded on the fly based on the LibOptions settings} AddScript(slPascal).LoadCodeFromFile(ABasePath + MyMainUnitName + '.code'); Execute; end;



The font keeps resetting to FixedSys when trying to change it
TAdvMemo requires, just like most syntax highlighting editors like the Delphi code editor or Visual Studio code editor, that a fixed size font is used. Examples of such fixed size fonts are Courier, FixedSys, Lucida, Terminal... When trying to set a non fixed font (like Tahoma, Arial), TAdvMemo will reset the font automatically to a fixed size font.



Disable edit control but allow to change text via button
If EditBtn.ReadOnly is set to true, the full control becomes readonly, meaning the edit control text can't be changed and the inplace button control is disabled. If it is desired that the editor control is readonly but the button is still active, set EditBtn.EditorEnabled = false.



Disable edit control but allow to change text via button
If AdvEditBtn.ReadOnly is set to true, the full control becomes readonly, meaning the edit control text can't be changed and the inplace button control is disabled. If it is desired that the editor control is readonly but the button is still active, set AdvEditBtn.EditorEnabled = false.



FTP Upload
WebCopy.Items.Clear; with WebCopy.Items.Add do begin ftphost := 'ftp.myserver.com'; ftpuserid := 'myusername'; ftppassword := 'mypassword'; protocol := wpFtpUpload; targetdir := 'folderonftp'; // path to use on FTP server targetfilename := 'filenameonftp.zip'; // filename to use on FTP server url := 'c:\tem\localfile.txt'; // local file end; WebCopy.Execute;



FTP Download
with WebCopy.Items.Add do begin FTPHost := ftp.tmssoftware.com FTPUserID := 'myuserid'; FTPPassword := 'mypassword'; URL := 'webcopy.zip'; Protocol := wpFTP; FileDate := EncodeDate(2002,3,18); CopyNewerOnly := true; TargetDir := 'c:\temp'; end; WebCopy.Execute;



Modifying a single series data point value in code
If a data value changes after it was added to the series, it is easy to update the value at a later time via code. To do this, it is required to know the index of the pane, the index of the series and the index of the data point in the series. This example code snippet changes the third datapoint of first serie in the first pane of the chart:
AdvChartView1.BeginUpdate; AdvChartView1.Panes[0].Series[0].Points[2].SingleValue := Random(100); AdvChartView1.EndUpdate;