Delphi

Delphi - Create class from a string

一个人想着一个人 提交于 2020-01-11 17:27:47
问题 I got code like this name := 'Foo'; If name = 'Foo' then result := TFoo.Create else if name = 'Bar' then result := TBar.Create else if name = 'FooFoo' then result := TFooFoo.Create; Is there a way just to do result := $name.create or some way of creating class based of a variable value? All the classes extended the same base class. 回答1: Starting with Delphi 2010, the enhanced RTTI allows you do this without having to creating your own Class Registry. Using the RTTI Unit you have several

Delphi - Create class from a string

十年热恋 提交于 2020-01-11 17:27:08
问题 I got code like this name := 'Foo'; If name = 'Foo' then result := TFoo.Create else if name = 'Bar' then result := TBar.Create else if name = 'FooFoo' then result := TFooFoo.Create; Is there a way just to do result := $name.create or some way of creating class based of a variable value? All the classes extended the same base class. 回答1: Starting with Delphi 2010, the enhanced RTTI allows you do this without having to creating your own Class Registry. Using the RTTI Unit you have several

How can I make my form resize more smoothly?

淺唱寂寞╮ 提交于 2020-01-11 15:51:08
问题 When resizing a form with many controls, the form looks bad because of flickering. What are some tips to have a smoother form resizing? 回答1: procedure TForm1.WMEnterSizeMove(var Message:TWMMove); begin Self.DisableAlign; end; procedure TForm1.WMExitSizeMove(var Message:TWMMove); begin Self.EnableAlign; end; 回答2: Try using WM_SETREDRAW (not LockWindowUpdate). You might also have a look at DeferWindowPos. 回答3: Complex forms are often made up of nested panels, and the repaint process may cause

Sorting TSTringList Names property as integers instead of strings [duplicate]

你离开我真会死。 提交于 2020-01-11 12:58:43
问题 This question already has answers here : How can I get TStringList to sort differently in Delphi (3 answers) Closed 6 years ago . I have a large file of text data where each line looks like such 10005=08/18/09,No BS,25094,wrg1 and the data is out of order (i.e. the number before the equal sign) I load this file into a StringList as Name Value pairs. The TStringList sort function does not of course because the numbers are strings and not integers. How can i get these into order before loading

Delphi: Easiest way to search for string in memorystream

孤人 提交于 2020-01-11 12:33:24
问题 What's the easiest way to search for a string within a memory stream (and multiple strings) and return true or false? 回答1: var ms:TMemoryStream; strS:TStringStream; aStr:string; aPos:integer; found:boolean; begin ms:=TMemoryStream.Create; ms.LoadFromFile('c:\aFile.txt'); strS:=TStringStream.Create; strS.LoadFromStream(ms); aPos:=pos(aStr,strS.dataString); found:=aPos>0; end; TStringStream is an often forgetten but very useful tool - easier and safer than messing with pChars, etc. For multiple

Service OnExecute fails, spawned thread is not executed

有些话、适合烂在心里 提交于 2020-01-11 12:01:50
问题 First go at starting my own service in Delphi 7. Followed the docs and made the service spawn a custom thread that beeps and logs. Only it doesn't. Last attempt was to put the same beep and log code in OnExecute event procedure, but when I start the service I get a Windows dialog saying that it was started and then stopped again. There should be something obvious that I've overlooked in this code. Could you have a look? I'll also accept links to simple, working, downloadable service example

turn off delphi exceptions in run time in delphi

霸气de小男生 提交于 2020-01-11 11:59:48
问题 is there any way to turn off exception message showing during run-time in Delphi application? i think there must be a directive to turn off exception message but i cant remember it. 回答1: Most exception messages can be suppressed by handling the TApplication.OnException event. The application object only displays an exception message if there isn't a handler assigned to that event. You're welcome to call TApplication.ShowException in your handler for certain exceptions if you want. That event

Set some cells in TDbGrid to editable

好久不见. 提交于 2020-01-11 11:52:28
问题 I want only some cells editable in a TDBGrid. In a given column, some but not all cells will be editable, so I can't just set Column.ReadOnly for the entire column and then leave it that way. What events are best to use so I can get control when a cell is entered. I might use TDbGrid.ColumnEnter to catch horizontal movement and TDataSet.AfterScroll for vertical movement in the grid. Or I could perhaps use TDBGrid.DrawColumnCell (which I'm already using to change the color of some cells...)

Set some cells in TDbGrid to editable

落花浮王杯 提交于 2020-01-11 11:52:13
问题 I want only some cells editable in a TDBGrid. In a given column, some but not all cells will be editable, so I can't just set Column.ReadOnly for the entire column and then leave it that way. What events are best to use so I can get control when a cell is entered. I might use TDbGrid.ColumnEnter to catch horizontal movement and TDataSet.AfterScroll for vertical movement in the grid. Or I could perhaps use TDBGrid.DrawColumnCell (which I'm already using to change the color of some cells...)

Get thread start address

佐手、 提交于 2020-01-11 11:19:08
问题 I'm writing a process viewer, its 99% complete, I just need get the start address of a process' thread, but I don't know how do it. Can anyone help-me? :/ Thx 回答1: You can use the NtQueryInformationThread function passing the ThreadQuerySetWin32StartAddress value of the THREAD_INFORMATION_CLASS enumeration as parameter. check this sample app {$APPTYPE CONSOLE} {$R *.res} uses TlHelp32, Windows, SysUtils; const THREAD_QUERY_INFORMATION = $0040; STATUS_SUCCESS = $00000000;