Quantcast
Channel: Programmer's Town - Delphi & Builder
Viewing all 704 articles
Browse latest View live

File-> Clipboard....... Clipboard-> the File

$
0
0

Kind day of the Lord!
It is necessary to import a file to the buffer and it is reverse
I do so
[spoiler]

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;
Dialogs, StdCtrls, Clipbrd;
type
TForm1 = class (TForm)
Button1: TButton;
Button2: TButton;
Button3: TButton;
procedure Button1Click (Sender: TObject);
procedure Button2Click (Sender: TObject);
procedure Button3Click (Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
procedure CopyStreamToClipboard (fmt: Cardinal; S: TStream);
var
hMem: THandle;
pMem: Pointer;
begin
Assert (Assigned (S));
S.Position: = 0;
hMem: = GlobalAlloc (GHND or GMEM_DDESHARE, S.Size);
if hMem <> 0 then
begin
pMem: = GlobalLock (hMem);
if pMem <> nil then
begin
try
S.Read (pMem ^, S.Size);
S.Position: = 0;
finally
GlobalUnlock (hMem);
end;
Clipboard. Open;
try
Clipboard. SetAsHandle (fmt, hMem);
finally
Clipboard. Close;
end;
end {If}
else
begin
GlobalFree (hMem);
OutOfMemoryError;
end;
end {If}
else
OutOfMemoryError;
end; {CopyStreamToClipboard}
procedure CopyStreamFromClipboard (fmt: Cardinal; S: TStream);
var
hMem: THandle;
pMem: Pointer;
begin
Assert (Assigned (S));
hMem: = Clipboard. GetAsHandle (fmt);
if hMem <> 0 then
begin
pMem: = GlobalLock (hMem);
if pMem <> nil then
begin
try
S.Write (pMem ^, GlobalSize (hMem));
S.Position: = 0;
finally
GlobalUnlock (hMem);
end;
end {If}
else
raise Exception. Create (' CopyStreamFromClipboard: could not lock global handle ' +
' obtained from clipboard! ');
end; {If}
end; {CopyStreamFromClipboard}
procedure SaveClipboardFormat (fmt: Word; writer: TWriter);
var
fmtname: array [0. 128] of Char;
ms: TMemoryStream;
begin
Assert (Assigned (writer));
if 0 = GetClipboardFormatName (fmt, fmtname, SizeOf (fmtname)) then
fmtname [0]: = #0;
ms: = TMemoryStream. Create;
try
CopyStreamFromClipboard (fmt, ms);
if ms. Size> 0 then
begin
writer. WriteInteger (fmt);
writer. WriteString (fmtname);
writer. WriteInteger (ms. Size);
writer. Write (ms. Memory ^, ms. Size);
end; {If}
finally
ms. Free
end; {Finally}
end; {SaveClipboardFormat}
procedure LoadClipboardFormat (reader: TReader);
var
fmt: Integer;
fmtname: string;
Size: Integer;
ms: TMemoryStream;
begin
Assert (Assigned (reader));
fmt: = reader. ReadInteger;
fmtname: = reader. ReadString;
Size: = reader. ReadInteger;
ms: = TMemoryStream. Create;
try
ms. Size: = Size;
reader. Read (ms.memory ^, Size);
if Length (fmtname)> 0 then
fmt: = RegisterCLipboardFormat (PChar (fmtname));
if fmt <> 0 then
CopyStreamToClipboard (fmt, ms);
finally
ms. Free;
end; {Finally}
end; {LoadClipboardFormat}
procedure SaveClipboard (S: TStream);
var
writer: TWriter;
i: Integer;
begin
Assert (Assigned (S));
writer: = TWriter. Create (S, 4096);
try
Clipboard. Open;
try
writer. WriteListBegin;
for i: = 0 to Clipboard.formatcount - 1 do
SaveClipboardFormat (Clipboard. Formats [i], writer);
writer. WriteListEnd;
finally
Clipboard. Close;
end; {Finally}
finally
writer. Free
end; {Finally}
end; {SaveClipboard}
procedure LoadClipboard (S: TStream);
var
reader: TReader;
begin
Assert (Assigned (S));
reader: = TReader. Create (S, 4096);
try
Clipboard. Open;
try
clipboard. Clear;
reader. ReadListBegin;
while not reader. EndOfList do
LoadClipboardFormat (reader);
reader. ReadListEnd;
finally
Clipboard. Close;
end; {Finally}
finally
reader. Free
end; {Finally}
end; {LoadClipboard}
//Examples:
{Save Clipboard}
procedure TForm1.Button1Click (Sender: TObject);
var
ms: TMemoryStream;
begin
ms: = TMemoryStream. Create;
try
SaveClipboard (ms);
ms. SaveToFile (' c:\temp\save.dat ');
finally
ms. Free;
end; {Finally}
end;
{Clear Clipboard}
procedure TForm1.Button2Click (Sender: TObject);
begin
clipboard. Clear;
end;
{Restore Clipboard}
procedure TForm1.Button3Click (Sender: TObject);
var
fs: TfileStream;
begin
fs: = TFilestream. Create (' C:\Temp\load.dat ', fmOpenRead);
try
LoadClipboard (fs);
finally
fs. Free;
end; {Finally}
end;
end.

[/spoiler]
Error here
reader: = TReader. Create (S, 4096);
Prompt how to correct... Thanks
(Like in Null I fall)


Json To Delphi Class

Delphi XE+Android+TStringStream. DataString

$
0
0

Application at handling of a line takes off: s: = ss. DataString
Here the code:

var
tt:TMemoryStream;
ss:tstringstream;
s:string;
...
begin
...
tt. LoadFromFile ('/sdcard/DCIM/Camera ' + ' /IMG_20161107_155217.jpg ');
tt. SaveToStream (ss);
s: = ss. DataString;
...

Error:
No mapping for Unicode cgaracter exists in multy-byte code page
Prompt how to solve?

DLL from Visual C# in Delphi 2010

$
0
0

Friends, prompt as it is possible to use in Delphi 2010 dll, written in Visual C# 2010? And whether generally it is possible. I tried the elementary. At pushing the button, in the field  the text which I transferred in library should boot.  simply accepts a line and returns it. I give Kod Delfi of the project with the form, the button and a field  more low. Even more low the code  written in C#. And even more low the code , written in . One works, another is not present.
The code  the project:

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;
Dialogs, IdTCPConnection, IdTCPClient, IdHTTP, IdBaseComponent, IdComponent;
IdIOHandler, IdIOHandlerSocket, IdIOHandlerStack, IdSSL, IdSSLOpenSSL;
StdCtrls;
type
TForm1 = class (TForm)
IdSSLIOHandlerSocketOpenSSL1: TIdSSLIOHandlerSocketOpenSSL;
IdHTTP1: TIdHTTP;
Button1: TButton;
Memo1: TMemo;
procedure Button1Click (Sender: TObject);
private
{Private declarations}
public
{Public declarations}
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
//Function from 
function getText (_s: string): string; stdcall; external ' GetInnerText.dll ';
procedure TForm1.Button1Click (Sender: TObject);
begin
//I transfer there the text which it returns reversely
memo1.Text: = getText ('  ');
end;
end.

Code , written in Visual C# 2010:

using System;
using System. Collections. Generic;
using System. Linq;
using System. Text;
public class GetInnerText
{
public static string getText (string _s)
{
return _s;
}
}

What do I do not so?
, written in most  works. Here its code:

library GetInnerText;
uses
SysUtils;
Classes;
Forms;
{$R *.RES}
function getText (_s: string): string; stdcall; export;
begin
result: = _s;
end;
exports getText;
begin
end.

To normalize , abbreviations

$
0
0

Whether there is such function for Delphi which leads to a normal type of a surname, names etc.?
For example, the user  IVAN entered, and it made Ivanov Ivan.
But here it is necessary to consider abbreviations still. For example,  should remain .

Stream write error

$
0
0

Help, in the program sometimes (periodically) there is a situation at discovery of a file from Blob fields

TBlobField (DM.qAttachments. FieldByName (' FILE_BLOB ')).SaveToFile
(extractfilepath (paramstr (0)) + '\Temp \' + DM.qAttachments. FieldByName
(' FILE_NAME ').asString);
ShellExecute (0, ' Open ';
PChar (extractfilepath (paramstr (0)) + '\Temp \' + DM.qAttachments. FieldByName
(' FILE_NAME ').asString), nil, nil, 1);

The data source is opened, I will not understand why so happens?

Creation of a flow and performance of procedures

$
0
0

All kind day! There was a necessity to use in the program flows, with flows work for the first time. It is necessary, that at pushing the button there was a flow and in it certain procedure was fulfilled. As I do it:
In type I register:

TMyThread = class (TThread)
protected
procedure Execute; override;
end;

And var:

MyThread: TMyThread;

On the button I register:

procedure TForm4.btnMonitoringClick (Sender: TObject);
begin
MyThread: = TMyThread. Create (false);
MyThread. FreeOnTerminate: = true;
MyThread. Priority: = tpLower;
MyThread. Resume;
end;

Also I create procedure TMyThread. Execute:

procedure TMyThread. Execute;
var
Ini: TIniFile;
f: TStrings;
s: string;
begin
Form4.body. PageIndex: = 1;
Form4.readServices;
Form4.readARMS;
Form4.readOracle;
Ini: = TIniFile. Create (ExtractFilePath (Application. ExeName) + ' system\system.t ');
Ini. WriteString (' monitoring ', ' lastrun ', DateTimeToStr (now));
Ini. WriteString (' monitoring ', ' user ', Form2.ComboBox1.Text);
Ini. Free;
Form4.checkSOAP;
Form4.checkARMS;
Form4.checkOracle;
Form4.saveLogWeb;
Form4.saveLogArm;
Form4.saveLogOra;
f: = TStringList. Create;
f. LoadFromFile (ExtractFilePath (Application. ExeName) + ' system\actions.log ');
s: = DateTimeToStr (now) + ' - ' + Form2.ComboBox1.Text + ' - ' + Form2.ComboBox2.Text + ' - ' + Form4.Label5.Caption;
f. Add (s);
f. SaveToFile (ExtractFilePath (Application. ExeName) + ' system\actions.log ');
end;

Question the first: whether the code is correctly written?
And at once the second question: apparently, the code is written incorrectly since the program works incorrectly and hangs up.
Prompt, please, where exactly spelling errors how correctly to write that is missed and if there is any material on flows - share, please.
Such code has been written by an example found on open spaces of the Internet.

Objects USER

$
0
0

Such impression that leak.
Suddenly from time to time started to send screenshots of the following content:
"System Error. Code: 1158.
Current process used all system resolutions on object management of the manager of windows ".
The project old, VCL, written on D6
Launched the test of discovery-closing of this window. Received interesting results.
Window MDI. Forms Tfrm. Create (Owner), is deleted - in FormClose Action: = caFree.
Originally objects USER in the manager of tasks ~200.
So, on the timer 1 second I do:
20 times Create/Close - number of objects USER grow (in the manager of tasks) to ~1400. Does not grow Further, it is dropped, but mines value already ~700.
60 times Create/Close - number of objects USER grow (in the manager of tasks) to ~4000. Does not grow Further, it is dropped, but mines value already ~1300.
It very much was not pleasant to me. Like restriction - 10000. And in the program more many similar windows, and everyone as creates such "not scrubbed" objects till the certain moment that as a result and can lead to an error.
Made other test. The empty project (he in nesting), in it Form1 - MDIForm, added MDIChild - TfrmTestForm1.
Launched a cycle from 1 to 1000 by the button.
At start Project1.exe ate 27 objects User. After working off btnTest1Click - 1027. After restart btnTest1Click - too 1027.
Added TfrmTestForm2 - simply inherited from TfrmTestForm1.
Added btnTest2, launched.
After start - 28
After btnTest1Click - 1028
And here after btnTest2Click - 2028.
Such way added 8 more forms. As a result easily received the above described system mistake (1158) for objects USER passed through 10000 (without reaching at all to TfrmTestForm10).
Here under spoilers the project code, well and in nesting if who wants to try to launch. The especial request to try on D7 and D7 + - suddenly this bug there is corrected.
[spoiler]

program Project1;
uses
Forms;
Unit1 in ' Unit1.pas' {Form1};
Unit2 in ' Unit2.pas' {frmTestForm1};
{$R *.res}
begin
Application. Initialize;
Application. CreateForm (TForm1, Form1);
Application. Run;
end.

[/spoiler]
[spoiler]

unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;
Dialogs, ExtCtrls, StdCtrls, Unit2;
type
TForm1 = class (TForm)
btnTest2: TButton;
btnTest3: TButton;
btnTest4: TButton;
btnTest1: TButton;
btnTest5: TButton;
btnTest7: TButton;
btnTest8: TButton;
btnTest9: TButton;
btnTest6: TButton;
btnTest10: TButton;
procedure btnTest2Click (Sender: TObject);
procedure btnTest3Click (Sender: TObject);
procedure btnTest4Click (Sender: TObject);
procedure btnTest5Click (Sender: TObject);
procedure btnTest6Click (Sender: TObject);
procedure btnTest7Click (Sender: TObject);
procedure btnTest8Click (Sender: TObject);
procedure btnTest9Click (Sender: TObject);
procedure btnTest10Click (Sender: TObject);
procedure btnTest1Click (Sender: TObject);
private
//
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
const
MAX_TEST_ITERATION = 1000;
type
TfrmTestForm2 = class (TfrmTestForm1)
end;
TfrmTestForm3 = class (TfrmTestForm1)
end;
TfrmTestForm4 = class (TfrmTestForm1)
end;
TfrmTestForm5 = class (TfrmTestForm1)
end;
TfrmTestForm6 = class (TfrmTestForm1)
end;
TfrmTestForm7 = class (TfrmTestForm1)
end;
TfrmTestForm8 = class (TfrmTestForm1)
end;
TfrmTestForm9 = class (TfrmTestForm1)
end;
TfrmTestForm10 = class (TfrmTestForm1)
end;
procedure TForm1.btnTest1Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm1;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm1.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest2Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm2;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm2.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest3Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm3;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm3.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest4Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm4;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm4.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest5Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm5;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm5.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest6Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm6;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm6.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest7Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm7;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm7.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest8Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm8;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm8.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest9Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm9;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm9.Create (Self);
frm. Close;
end;
end;
procedure TForm1.btnTest10Click (Sender: TObject);
var
i: Integer;
frm: TfrmTestForm10;
begin
for i: = 1 to MAX_TEST_ITERATION do begin
frm: = TfrmTestForm10.Create (Self);
frm. Close;
end;
end;
end.

[/spoiler]
[spoiler]

unit Unit2;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms;
Dialogs;
type
TfrmTestForm1 = class (TForm)
procedure FormClose (Sender: TObject; var Action: TCloseAction);
private
{Private declarations}
public
{Public declarations}
end;
implementation
{$R *.dfm}
procedure TfrmTestForm1.FormClose (Sender: TObject; var Action: TCloseAction);
begin
Action: = caFree;
end;
end.

[/spoiler]
Who does not prompt, in what side to dig? How to force VCL not to store any cache of not closed objects USER, and to clean at once? Whether it is possible?
Thanks.


Component EHLIB

$
0
0

Good afternoon. Such is a question Where it is possible to download freeware the version of the given library for RAD XE10 Seattle. Very much it is necessary. In advance thanks.

FireDAC - Access Violation

$
0
0

What it for a hogwash in FairDake?

type
TMyMemTable=class (TFDMemTable)
private
FAdapter: TFDTableAdapter
public
constructor Create (AOwner:TComponent); Override;
end;
constructor TXDataSet. Create (AOwner: TComponent);
begin
inherited;
FAdapter: = TFDTableAdapter. Create (nil);
Adapter: = FAdapter;//<<Access Violation, version 1
Adapter: = TFDTableAdapter. Create (Self);//<<so too Access Violation, version 2
end;

Prompt Virtual Dataset?

$
0
0

Whether there is free analog MemData/VirtualTable?

The best CPU for operation with Delphi

$
0
0

I have the project more than 1 million lines, compilation and operation with IDE began to brake noticeably. I plan to replace old Sandy Bridge Core i3 with something . And here there was a question that for Delfi : speed in a multiflow or speed of one kernel?
In other words, what will be faster, Core i7 7700K (4 core, 4.2 Ghz) or 6800K (6 core, 3.4 Ghz) for Delphi?

TList = TThreadList. LockList - periodic dropping of the data in a flow

$
0
0

I want to drop periodically the data and tred-sheet in sheet, and then this sheet to start up in handling, thus tred-sheet should be devastated and be free for reception of the new data.
What of these a construction correct:
1.

List: = ThreadList. LockList;
ThreadList. Clear;
ThreadList. Unlock;
while... List. Count - 1 do
begin
DoLongJob;
end

2.

List. AddRange (ThreadList. LockList. ToArray);
ThreadList. Clear;
ThreadList. Unlock;
while... List. Count - 1 do
begin
DoLongJob;
end

firedac and postgresql

$
0
0

The people help please. Wrote function on postgresql returning table. I cause FDStoredProc. Active: = true
Also the error falls out: cached plan must not change result type. In function there is a tempo table and sampling of this table is returned.
If in function to remove the tempo table and to deduce result directly, and in  in FDQuery to write:

create temp table temptable...
Insert Into temptable
Select *
From function ()
Select *
from temptable

the dial-up successfully opens but at saving of changes (together with FDUpdateSQL) the error falls out:
[FireDAC] [DApt]-400. Update command updated [0] instead of [1] record. Possible reasons: update table does not have PK or row identifier, record has been changed/deleted by another user.

MediaPlayer

$
0
0

Why does not play back music?
At pushing the button:

MediaPlayer1.FileName: =' ';
MediaPlayer1.Play;

Lazarus64, Linux64, CEF3. All fresh: TApplication. HandleException Out of memory

$
0
0

I can not  chrome in a window. The component breathes, but when I load page:
./project1
[0105/000759:WARNING:audio_manager.cc (317)] Multiple instances of AudioManager detected
[0105/000759:WARNING:audio_manager.cc (278)] Multiple instances of AudioManager detected
[FORMS.PP] ExceptionOccurred
Sender=EOutOfMemory
Exception=Out of memory
Stack trace:
$00000000004361CF
TApplication. HandleException Out of memory
Stack trace:
$00000000004361CF
Segmentation fault

ADOQuery. Communication link failure

$
0
0

Kind time of days!
I use component ADODB on Delphi 7.
There is an application with the timer for 10 seconds.
In the timer code there is a reversal to basis SQL through ADOQuery.
All code thrust in the handler try-except where the error text is deduced in separate Memo.
And so, at origin of any (any) error, we tell "TCP a name it is not known" (precisely I do not remember the text), the program deduces the text in Memo goes further. At following actuating of the timer, again tries and if a connection successful the data turns out.
But if I pull out  from  there is error Connection link failure. It is caught, deduced, and at cable connection reversely is recovered nothing. Timer pass again receives Connection link failure.
Looked  through . On lines

ADOQuery. Active
ADOQuery. ExecSQL

There is this error, directly ahead of them the line of connection which, as well as all code, is in try-except is set.
Can prompt why restarting of my program helps only?

The strange behavior tadoquery

$
0
0

Good evening
Faced a problem when tadoquery hangs up on request performance to sql server, generally on it is dead, I cause in it stored procedure with parameters, at what if to cause it in studio it is fulfilled for pair seconds. If to cause procedure in TADOStoredProc all quickly works, but it is not clear, some years tadoquery worked, who can prompts the reason?

Whether there is analog UnicodeString for Delphi2007?

$
0
0

All greetings.
Actually a question:
What was analog UnicodeString for Delphi2007?
Was specific functions Pos (), Length (), Copy (), Delete () for operation with  in the lines of type WideString are necessary. I.e. functions in D2007 are present, but for some reason I doubt that they correctly work with  in the lines.

Component for the browser.

$
0
0

Kind day.
I want to write " " - for the personal purposes (on operation)... But that that is in VCL not all is able to do, i.e. does not load some sites correctly.
How it is possible to correct this business?
Thanks.

Viewing all 704 articles
Browse latest View live