📄 delsec05.txt
字号:
A: Form scrolling is accomplished by modifying the VertScrollbar
or HorzScrollbar Postion properties of the form. The following
code demonstrates how to do this:
procedure TForm1.FormKeyDown(Sender: TObject; var Key: Word;
Shift: TShiftState);
const
PageDelta = 10;
begin
With VertScrollbar do
if Key = VK_NEXT then Position := Position+PageDelta
else if Key = VK_PRIOR then Position := Position-PageDelta;
end;
Note: This may not work well if the active control uses PgUp & PgDn,
too, like a TMemo.
------------------------------------------------------------------------
Q: "Is there a way to fill a TListbox or TMemo in one shot?"
A: To fill multiple lines of a TListbox or TMemo component the SetText
method can be used. The null terminated string passed to the
SetText method is a concatination of each line of text delimeted
by a carriage return character #13 in between. For example,
the follow statement:
Listbox1.Items.SetText('aaaaa'#13'bbbbb'#13'ccccc')
will display the following in a listbox window:
aaaaa
bbbbb
ccccc
Note: The preferred method of filling a listbox or memo is with the
Add method of their Items and Lines properties, respectfully.
------------------------------------------------------------------------
Q: "Is it possible to create something like the Control Array in Visual
Basic? For example, I want a group of buttons with a common event
handler whereby the event handler picks up an integer value for the
particular button. In Visual Basic this would be done via the
Control Array index."
A: One way do to this is to set the Tag field for each button to a
different number and then create a common OnClick event handler
that looks at the Sender's Tag field. Assign the same OnClick
event handler to all the buttons in the group. And then the
OnClick event handler would look something like this:
procedure TForm1.Button1Click(Sender: TObject); var cap: string;
begin
case TButton(sender).Tag of
1: ShowMessage('1st Button Pressed');
2: ShowMessage('2nd Button Pressed');
3: ShowMessage('3rd Button Pressed');
end;
end;
------------------------------------------------------------------------
Q: "How can a new component be added to a page of a
TTabbedNoteBook at run time? How do I determine
what the parent will be for the new component?"
A: To add a component to a TabbedNotebook page at run-time a
pointer to the desired page must be assigned to the new
component's Parent property before it can be shown. The way to
access all the pages of a TTabbedNotebook at run-time is with
the Objects array property of the TabbedNotebook's Pages property.
In other words, the page components are stored as objects attached
to the page names in the Pages string list property. The follow
demonstrates the creation of a button on the second page of
TabbedNotebook1:
var
NewButton : TButton;
begin
NewButton := TButton.Create(Self);
NewButton.Parent := TWinControl(TabbedNotebook1.Pages.Objects[1])
...
This is how a TNotebook page would be used as a parent to a newly
created component on that page:
NewButton.Parent := TWinControl(Notebook1.Pages.Objects[1])
This is how a TTabSet tab page would be used as a parent to a
newly created component on that tab page:
NewButton.Parent := TWinControl(TabSet1.Tabs.Objects[1])
------------------------------------------------------------------------
Q: "Are there any vertical ( side of the page ) tab components
available, commercial, shareware or freeware."
A: TurboPower's Orpheus product will support this. GO TURBOPOWER
for more information.
------------------------------------------------------------------------
Q: "Is there an easy way to get CopyToClipboard, CutToClipboard etc.
to know to use the TEdit that has focus?
A: Simply check to see if the ActiveControl is of type TEdit and then
do the desired cut, copy or paste operation. For example:
if (ActiveControl is TEdit) then
TEdit(ActiveControl).CopyToClipboard;
------------------------------------------------------------------------
Q: "Does a TDBGrid component have an OnMouseDown, OnMouseUp and
OnMouseMove events?"
A: The events are there, but they aren't published. You could
create a simple decendant of TDBGrid and publish them.
------------------------------------------------------------------------
Q: "Does Delphi grab system resources when displaying and closing
modal dialogs? For example, the following code decreases the
system resources every time it is used to show a modal dialog."
ModalForm1 := TModalForm1.Create(Self);
ModalForm1.ShowModal;
A: Without an OnClose event handler that sets Action parameter to
caFree, your code is creating a new form with each call to
TModalForm1.Create(Self), but the previously created form is
never destroyed. All previous instances of the "ModalForm1"
forms are floating around in Windows.
The Free method of a form can also be used to free its resources.
This is demonstrated below:
try
ModalForm1.ShowModal;
{ other stuff here }
finally
ModalForm1.Free;
end;
------------------------------------------------------------------------
Q: "What is the best way to create a radio button group and
place radio buttons on it? It seems that you can create a
Radio Group then drop Radio Buttons on it or you can
create the group and enter values into the Items properties
for the titles (captions) of the radio buttons and have
Delphi place them in the group?"
A: If you're going to use a radio group, you need to create your
radio buttons using the Items string list. Radio buttons
don't have to be in a group, which is why the plain radio
button component is available.
------------------------------------------------------------------------
Q: "Is there a way to make sure the window that is holding a form
or an image component is byte-aligned?"
A: Override the CreateParams method:
procedure TMyForm.CreateParams(var Params:TCreateParams);
begin
inherited CreateParams(Params);
Style := Style or CS_BYTEALIGNWINDOW;
end;
Note: Byte alignment is less of a big deal than the Windows docs
imply. It is only significant on monochrome, EGA, and 16 color
VGA video modes. All higher video modes are always byte-aligned.
------------------------------------------------------------------------
Q: What is the order of event handlers when a form is created
and shown?
A: When a form is created the event handlers are executed in the
following order: OnCreate, OnShow, OnPaint, OnActivate, OnResize
and OnPaint again.
------------------------------------------------------------------------
Q: "Why does the error 'Cannot change Visible in OnShow or OnHide'
occur when the FormStyle property of a form is changed in the
OnActivate event?
A: The FormStyle property defines how the window gets created and
is usually set in the OnCreate event, however, it can changed
after the window handle has been created, just not during the
OnActivate, OnShow or OnHide events. The issue here is with the
mode that the system is in during OnShow and OnHide events.
------------------------------------------------------------------------
Q: "How can I make components look sunken and raised?
A: To make a component look raised or lowered place it on
a TBevel or TPanel component which both have properties to
raise or lower their frames.
------------------------------------------------------------------------
Q: Where is the source code for the tabbed controls (i.e.
TTabbedNotebook)?
A: The source code files shipped with Delphi does not contain the
source for the tabbed controls because of legal reasons. However,
the interface source for the tabbed controls is provided
in the DELPHI\DOC directory with an INT extension.
Note: Registered owners of the Delphi RTL source code can request
the TTabSet and TTabbedNotebook source code from Borland Corporate
Affairs. Instructions are in the RTL source readme.
------------------------------------------------------------------------
Q: "What is the memo field size in Delphi?"
A: Microsoft's edit control that is built-in to Windows and used
by Delphi's TEdit and TMemo wrapper classes has a maximum
capacity of 32k. The Delphi wrapper classes do some special
things to allow every edit and memo control on a form to
contain up to 32k each. Normally all edit controls in an
application would be limited to 32k collectively.
------------------------------------------------------------------------
Q: "How can I make a field in the TGrid component not show up?"
A: This can be accomplished by either removing the field entirely
from the Fields Editor's field list or by setting the Visible
property of the field to False.
------------------------------------------------------------------------
Q: "Is there a way to put a wallpaper background on an MDI
application?"
A: There is a sample application that demostrates this in the VCL
section (5) of the Delphi forum under the name of MDI_BGRD.ZIP.
------------------------------------------------------------------------
Q: "Does Delphi have a currency/money component?"
A: No, bu there is a currency edit component in the VCL section of the
Delphi forum under the name of CURREDIT.ZIP.
------------------------------------------------------------------------
Q: "Where can I find out about VBX datatypes (i.e. TBasicString) and
the functions to manipulate these datatypes?"
A: First off, all VBX related datatypes and functions are in the
VBXCtrls unit which is Borland propriatary unit. Delphi does,
however, provide the interface section of this unit is in the
\DELPHI\DOC directory under the name of VBXCTRLS.INT. This is the
only real source of information on the contents of the VBXCtrls unit.
------------------------------------------------------------------------
Q: "What issues do I need to be aware of when developing applications
that will be ran on different screen resolutions (form scaling)?"
A: The following are issue to bear in mind when scaling Delphi
applications (forms) on different screen resolutions?
* Decide early on in the form design stage whether you're going to
allow the form to be scaled or not. The advantage of not scaling is
that nothing changes at runtime. The disadvantage of not scaling is
that nothing changes at runtime (your form may be far too small or
too large to read on some systems if it is not scaled).
* If you're NOT going to scale the form, set Scaled to False.
* Otherwise, set the Form's Scaled property to True.
* Set AutoScroll to False. AutoScroll = True means 'don't change the
form's frame size at runtime' which doesn't look good when the
form's contents do change size.
* Set the form's font to a scaleable TrueType font, like Arial.
MS San Serif is an ok alternate, but remember that it is still a
bitmapped font. Only Arial will give you a font within a pixel of
the desired height. NOTE: If the font used in an application is not
installed on the target computer, then Windows will select an
alternative font within the same font family to use instead.
This font may not match the same size of the original font any may
cause problems.
* Set the form's Position property to something other than poDesigned.
poDesigned leaves the form where you left it at design time, which
for me always winds up way off to the left on my 1280x1024 screen -
and completely off the 640x480 screen.
* Don't crowd controls on the form - leave at least 4 pixels between
controls, so that a one pixel change in border locations (due to
scaling) won't show up as ugly overlapping controls.
* For single line labels that are alLeft or alRight aligned, set
AutoSize to True. Otherwise, set AutoSize to False.
* Make sure there is enough blank space in a label component to allow
for font width changes - a blank space that is 25% of the length of
the current string display length is a little too much, but safe.
(You'll need at least 30% expansion space for string labels if you
plan to translate your app into other languages) If AutoSize is
False, make sure you actually set the label width appropriately.
If AutoSize is True, make sure there is enough room for the label
to grow on its own.
* In multi-line, word-wrapped labels, leave at least one line of
blank space at the bottom. You'll need this to catch the overflow
when the text wraps differently when the font width changes with
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -