Delphi

Delphi: TThreadList sometimes lock program

情到浓时终转凉″ 提交于 2020-01-07 09:52:11
问题 Sometimes this function locks my program, and it's freezes until i close it. What is wrong here ? function del_from_list(id:string):boolean; var i : integer; begin Result := True; try with global_list.LockList do begin for i:=0 to Count-1 do begin if Tthread_list(Items[i]).id = id then begin Delete(i); break; end; end; end; finally global_list.UnlockList; end; end; the class Tthread_list = class public id : string; constructor Create(const id: string); end; I'm adding to the list like that:

Delphi: TThreadList sometimes lock program

纵然是瞬间 提交于 2020-01-07 09:52:05
问题 Sometimes this function locks my program, and it's freezes until i close it. What is wrong here ? function del_from_list(id:string):boolean; var i : integer; begin Result := True; try with global_list.LockList do begin for i:=0 to Count-1 do begin if Tthread_list(Items[i]).id = id then begin Delete(i); break; end; end; end; finally global_list.UnlockList; end; end; the class Tthread_list = class public id : string; constructor Create(const id: string); end; I'm adding to the list like that:

How to generate a certain amount of numbers and spread them randomly across a grid?

荒凉一梦 提交于 2020-01-07 09:43:40
问题 I want to generate the number 2 5 times and the number 1 10 times. I'm trying to spread these across a String Grid in Delphi randomly. I also want to fill the rest of the grid that isn't 1 or 2 , with 0 's. I have no idea how to even start here. It would look something like this (P stands for player and there would only be 5 2's and 10 1's): https://gyazo.com/aeef05c3a92ce7847c0f42ad40faa733 回答1: Given a grid with dimensions m × n , create an array of length m * n . Put five 2's and 10 1's in

Inheritance/polymorphism concept

て烟熏妆下的殇ゞ 提交于 2020-01-07 09:24:03
问题 I have two binary files that contain a similar type of data so I want to create a unified viewer (TViewer) for both files. Some, methods are common for these two file types, some are not. So I created a base class TShape, and the from it TCircle and TTriangle. Pseudo code: TShape = class(TObject) function NoOfItems: integer; virtual; abstract; end; TCircle = class(TShape) function NoOfItems: integer; override; <---- The real implementation end; TTriangle = class(TShape) function NoOfItems:

Inheritance/polymorphism concept

∥☆過路亽.° 提交于 2020-01-07 09:23:05
问题 I have two binary files that contain a similar type of data so I want to create a unified viewer (TViewer) for both files. Some, methods are common for these two file types, some are not. So I created a base class TShape, and the from it TCircle and TTriangle. Pseudo code: TShape = class(TObject) function NoOfItems: integer; virtual; abstract; end; TCircle = class(TShape) function NoOfItems: integer; override; <---- The real implementation end; TTriangle = class(TShape) function NoOfItems:

Firemonkey Hints don't work in Delphi Seattle, for a project converted from XE7

南楼画角 提交于 2020-01-07 09:07:29
问题 I opened this demo in Delphi Seattle and it works like it should. When I open my program, and include the demo form it doesnt work. I cannot add hints to my controls. procedure TMainForm.FormCreate(Sender: TObject); application.ShowHint:=true; application.OnHint :=OnApplicationHint; end; procedure TMainForm.OnApplicationHint(Sender: TObject); begin caption := (Application.Hint); end; My program is converted from XE7 to Seattle. So what could be the difference? Where can i find the code that

What is the exact effect of TDataset.close() in Delphi?

孤街醉人 提交于 2020-01-07 09:03:33
问题 Why it is recommended to process a sql-query in Delphi in the following way?: dataset.close(); // ????? dataset.sql.clear(); // old sql-query gets deleted dataset.sql.add('your sql-query'); // here a query-String is added to your sql-object dataset.open(); // here your sql-query starts to work Can it be that closing of a sql-Object defines everytime a default state by which the former dataset resulting from the former sql-query is deleted? 回答1: When you open a dataset, it enables an active

What is the exact effect of TDataset.close() in Delphi?

杀马特。学长 韩版系。学妹 提交于 2020-01-07 09:03:31
问题 Why it is recommended to process a sql-query in Delphi in the following way?: dataset.close(); // ????? dataset.sql.clear(); // old sql-query gets deleted dataset.sql.add('your sql-query'); // here a query-String is added to your sql-object dataset.open(); // here your sql-query starts to work Can it be that closing of a sql-Object defines everytime a default state by which the former dataset resulting from the former sql-query is deleted? 回答1: When you open a dataset, it enables an active

How to handle TRegEx named capture groups that might be empty?

假装没事ソ 提交于 2020-01-07 08:55:09
问题 I have a regular expression with named capture groups, where the last group is optional. I can't figure out how to iterate the groups and properly deal with the optional group when it's empty; I get an EListOutOfBounds exception. The regular expression is parsing a file generated by an external system that we receive by email which contains information about checks that have been issued to vendors. The file is pipe-delimited; a sample is in the code below. program Project1; {$APPTYPE CONSOLE}

Get notified if cmd.exe fails to successfully move a file?

两盒软妹~` 提交于 2020-01-07 08:28:12
问题 I run cmd.exe to move a file with Administrator rights: ThisParams := '/C move ' + '"' + ThisSourceFile + '"' + ' ' + '"' + ATargetFile + '"'; Winapi.ShellAPI.ShellExecute(0, 'runas', 'cmd.exe', PChar(ThisParams), '', Winapi.Windows.SW_HIDE); Unfortunately, ShellExecute always gives back success, regardless of whether the move action was successful or not (the move action would fail for example if the target file exists and it is read-only or if the target disk is write-protected). So how can