Delphi

59K

Solutions

17K

Contributors

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

Share tech news, updates, or what's on your mind.

Sign up to Post

Is there a clean way to determine whether a particular file is locked in Windows?
Before updating my program I want to be sure no files in the installation folder are in use. This to prevent the update from failing.

I tried the following code:

function IsFileInUse(FileName: TFileName): Boolean;
var
  HFileRes: HFILE;
begin
  Result := False;
  if not FileExists(FileName) then Exit;
  HFileRes := CreateFile(PChar(FileName),
                         GENERIC_READ or GENERIC_WRITE,
                         0,
                         nil,
                         OPEN_EXISTING,
                         FILE_ATTRIBUTE_NORMAL,
                         0);
  Result := (HFileRes = INVALID_HANDLE_VALUE);
  if not Result then
    CloseHandle(HFileRes);
end;

Open in new window


and this one:

    Result := False;
    try
      fHandle := FileOpen(inFile, fmExclusive);

      if fHandle = -1 then
        result := True
      else
        FileClose(fHandle);
    except
      Result := True;
    end;

Open in new window


and this one ...

     
      try
        if FileExists( inFile ) then
        begin
          try
            fs := TFileStream.Create( inFile, fmOpenReadWrite or fmShareExclusive );
            Result := False;
          finally
            fs.Free;
          end;
        end;
      except
        Result := True;
      end;

Open in new window



But all three have the same problem: By testing whether the file is locked, it is  (sometimes) locked by the test itself.
Is there a better way to check whether a file is locked, or will every solution result in the same problems?
0
Get your problem seen by more experts
LVL 12
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

I'm trying to read an xml response from a api but I keep getting the following error:


How can I read the xml data if the response looks like this:
<status>success</status><statusmsg>online</statusmsg><vmstat>online</vmstat><hostname>quantum.vps</hostname><ipaddress>xxx.xx.xx.xxx</ipaddress>

Open in new window


My current code:
procedure TfrmMain.btn1Click(Sender: TObject);
var
  httpclient: TIdHTTP;
  doc: TXMLDocument;
  data: IXMLNode;
begin
  httpclient := TIdHTTP.Create(nil);
  try
    doc := TXMLDocument.Create(nil);
    try
      doc.XML.Text := httpclient.Get('https://site.com/api.php?action=status'); //Modified URL for experts exchange
      doc.Active := True;
      data := doc.DocumentElement;
      lbl1.Text := data.ChildNodes['status'].Text;
    finally
      doc.Free;
    end;
  finally
    httpclient.Free;
  end;
end;

Open in new window

0
In Delphi I'm looking for a way to clone a two forms (one that has an ancestor that inherits components and settings accordingly) into a new single form that has no ancestor requirement.

To try and describe this - let's say that I have two forms:

FORMANCESTOR contains 3 buttons on it sitting on a Panel. The captions on these buttons are set in FormAncestor, and Buttons are called BTN1, BTN2 and BTN3.

FORMCHILD is a descendant of FormAncestor so the panel with the 3 buttons inherits automatically and shows on FORMCHILD.  But FORMCHILD has BTN3's caption altered, and has a new 4th Button added to FORMCHILD.

What I would like to do is create a new form called FORMINDEPENDENT which has the 4 buttons and Panel, and inherits from TForm as opposed to TFormAncestor

I was just wondering if there is a standard way / correct method to merge / migrate / clone from decedents as per the above so that I have a new independent form that doesn't need to reference any ancestors and can just be a descendent directly from a TForm?

Thanks

Adam
0
I had this question after viewing TAdvStringGrid:  Cell's Background and Font color handling.

In a TAdvStringGrid, in grid.OnGetCellColor event-handler, I've set each cell of the fixed column to a different color:

ABrush.Color := GetMyCustomColor;

Open in new window


Now, when I click on a cell of this fixed column, in the grid.OnClickCell event-handler, I want to get the color of the clicked cell.

How can I do this?

I have tried:

grid.GetCellProperties(ACol, ARow).BrushColor)

Open in new window


But it does not work. I always get the same color: RGB(255, 255, 255).
0
I have quite normal parameter like:

Procedure Something(var test:integer);

In the form i have a global variabel (well global to that form) defied as:

  public
    { Public declarations }
   var gtest :integer;


Now i want to transfer the pointer from test to gtest.

gtest :=test; wont work. How should it be done?
0
I wish to send a message to all client connected to my server application which uses an Indy 10 TCP Server component in Embarcadero C++ builder  XE 10.2 .

I have written the following function  which is meant to iterate through all the client connections to my server but it doesn't work.

I need some help in how to iterate through the list returned by the  IdTCPServer1->Contexts->LockList()  function.
I have seen an example in Delphi but my attempt in translating to C++ builder doesn't work.


void TForm1::BroadcastMessage(UnicodeString mess)
{
	TList *ls;
	int n;
	TIdContext *c;

	try
	{
		ls = IdTCPServer1->Contexts->LockList();
                n = ls->Count;
		for(int i=0;i<n;i++)
		{
			c = (TIdContext *)(ls->Items[i]); // <------ This line  is where the coding is wrong
			c->Connection->IOHandler->WriteLn(mess);
		}
		IdTCPServer1->Contexts->UnlockList();
	}
	catch(...)
	{
		IdTCPServer1->Contexts->UnlockList();
	}
}
//---------------------------------------------------------------------------

Open in new window

0
Hello.

I want to make a snake game using DELPHI. The basic, the snake eats the apple and it grows longer. I have the apple generating in random places. The only thing that I cant get is the delay. So i need the blocks to follow the first block in a train effect, but so far they are all stuck together and when I change direction they all move together instead of being in a 'train' effect.

Can anyone help me? I don't know if the explanation was detailed enough.
Many Thanks
54999858925__AB9E1587-E48B-4EC4-B511.MOV
0
I need some assistance in writing a TCP Server in Embarcadero C++ builder XE 10.1 using  an Indy 10 TCP server VCL control.
How do I accept a connection from a client when using an Indy 10 VCL control TIdTCPServer ?
I imagine that I need to write some code in the OnConnect Event handler although logically one might expect a "BeforeConnect"  event handler .I haven't found any methods anywhere in the AContext or its members called Accept() ?
Also, my understanding is that  when a connection is established, the Execute event is invoked which supplies an AContext parameter which equates to a thread. Can I let the Execute event handler terminate and have a separate thread that manipulates the saved value of the AContext parameter in a list. the separate thread would poll round each AContext in the list  to independently send/receive data to/from the remote clients ?
0
Hi, i have an application running in a debian server, developed in delphi 7 for 32 bits, with postgresql as database, port 5433.
To get an easy way for updating the app, all the clients (windows platform, 32, 64 bits, xp, 7, and 10), reference the executable in the server, but execute it in a local folder, where an ini file configures the link to the database.
In a lot of customers (not all with a debian server, instead, there are windows servers and ubuntu server), and in this customer, this scheme works fine.
In one PC, with Win10, i have this strange problem:
1) if i use a link, that reference the exe in the server and execute the app, it doesn't work. I get an error (internal to the app), as if i can't reach postgresql server.
2) if i copy the exe, and execute in any folder, executing in the same folder as 1), the app works fine.
It seems to be something of the firewall... i disabled it.
It seems to be something of the antivirus... i disabled it (AVG).
pgAdmin, conects to the server.
I simply can't see any other posible solution...
Can anybody help?
Thanks!
0
Hi Experts,
In one of my screen i am getting Edatabase error exception when clicking on more than one records in a grid. The problem is as below.
I have a grid ( Dev express tcxgrid). Tableview data controller - Data source is linked with TDatasource. Dataset of Tdatasource is set to a Toraquery ( from dev art).

In grid i am displaying the fields from a temporary table. So in the screen i have a search button, on click of the search button i am executing a stored proc which actually loads the search result into a temporary table. something like below:

with datmodule1 do
begin
  with storedproc1 do
  begin
    try
        try
           execproc;
        except
            // some code not related to the issue
        end;
   finally
    unprepare;
  end;
end;

with toraquery1
begin
  close;
  sql.text := 'select * from tmptable1';   //records are inserted in this temp table in side the stored proc which gets executed above.
  open;
end;

Records are loaded in the screen. There is a checkbox type column in the grid which by default loaded as ticked. As i am inserting that field as 1 in the temp table which i have written inside the stored proc.

Then there is a button which deselect all the ticks, code for that is an update statement as below:

with Datamodule1 do
  begin
    with qryMisc do
    begin
      close;
      sql.text := 'Update tmptable1 set checked = 0';
      execsql;
    end;
    toraquery1.close;
    toraquery1.open;…
0
Introducing Cloud Class® training courses
LVL 12
Introducing Cloud Class® training courses

Tech changes fast. You can learn faster. That’s why we’re bringing professional training courses to Experts Exchange. With a subscription, you can access all the Cloud Class® courses to expand your education, prep for certifications, and get top-notch instructions.

I have a working system that uses SQL Express as the database.
On 2 computers, window 8.1, everything is okay.
I have just installed another computer with Windows 10 and the program brings an error when assigning MyQuery.FieldByName('MyDateField').AsDateTime to a DateTime variable.
It only happens on this computer.

I have installed the program on my development computer that is also Windows 10 and using SQL Express and have no problems.

The ShortDateFormat is the same on all computers.

1. The command ShowMessage(ShortDateFormat) displays the same on all computers 'd/MM/yyyy'
2. FieldByName('MyDateField').AsString on the working computers displays the date in the ShortDateFormat, like '31/12/1999'
3. FieldByName('MyDateField').AsString on the new computer displays the date as '1999-12-31'
4. FloatToStr(FieldByName('MyDateField').AsDateTime) on the new computer raises error "'1999-12-31' is not a valie date time."

All the settings are the same

I have never seen anything like that and I need your help here.

Using Delphi 7 and SDAC
0
Hello,

I need to use a SOAP interface of the Dogana in Italy.
I develop some code in delphi (berlin) using SOAPHTTPClient, but i become always this error:

"Impossibile passare dalla codifica corrente a quella specificata.
Line: 1
<?xml version="1.0" encoding="utf-8"?><s."

I try
HTTPRIO.Converter.Options:=HTTPRIO.Converter.Options+[soUTF8InHeader];
HTTPRIO.Converter.Options:=HTTPRIO.Converter.Options+[soUTF8EncodeXML];
HTTPRIO.HTTPWebNode.UseUTF8InHeader:=true;
HTTPRIO.Converter.Encoding := 'UTF-8';

Thank you for the help.

Andreas
0
I got a signed executable, when running on my local machine everything works fine but with one of our clients there is an issue when they try to run it from a network drive.
They get a "Open File - Security Warning" (see the image). When they run it from a local disk, there are no issues as well
network-drive-error.PNG
0
Hey,
I want to serialize an object to xml with delphi 7,  i searched but i didn't find a full solution, i think with HttpRio we can do it .
thank you in advance.
0
My Delphi application for Windows is packed in appx so I can have it published in Microsoft Store. At the first run, the app creates a folder in <user>AppData\Roaming to store there some files accessible for the users. Here's the code:

MyFolder:=GetSpecialFolderPath(CSIDL_APPDATA)+'\MyApp';
CreateDir(MyFolder);
TDirectory.SetAttributes(MyFolder,[TFileAttribute.faNormal]);

Open in new window


It works fine. When the app is running, the users can open its dialog windows, see this folder with all the files, read them or write into them. But only from the app! The mystery is that this new folder cannot be seen in Windows Explorer. Even in Command Prompt it seems non-existent!

Can anybody explain what this means?
0
Hi Guys,

The idFtp has an important event that gets the results, I don't know how to set / use the event when I create the idFtp in runtime. I need to
an example for it.  Below you can see my code and use it to give me an example.

Thanks a lot

  Function RunFTP( FtpServidor ,  FtpUsuario, FtpSenha, FtpPorta,  FtpAutentica, FtpCaminhoUpload, FtpCaminhoResposta: String): Boolean;

  Result := True

  if EstaVazio(FtpServidor) or EstaVazio( FtpUsuario ) or EstaVazio( FtpSenha ) or  EstaVazio( FtpAutentica ) or
     EstaVazio( FtpPorta )  {or EstaVazio( SmtpCaminhoUpload ) or EstaVazio( SmpCaminhoResposta )} then Begin
     ShowMessage('As configurações de FTP não estão completas no parceiro: ' + CodCad);
     Result := False;
     Exit;
  End;


  if FtpAutentica = '1' then
     FtpAut  := true
  else
     FtpAut  := false;


  IdFTP1 := TIdFTP.Create();
  IdFTP1.Disconnect;

  IdFTP1.Host     := FtpServidor;
  idFTP1.DirectoryListing.DirectoryName:= FtpCaminhoUpload;
  IdFTP1.Port     := Strtoint(FtpPorta);
  IdFTP1.Username := FtpUsuario;
  IdFTP1.Password := FtpSenha;
  IdFTP1.Passive  := FtpAut;

  try
     IdFTP1.Connect;
  except
     IdFTP1.Disconnect;
     IdFTP1.Connect;
     Result := False;
     Exit;
  end;

  BarraRotina('UP',Carquivo+iif(Tipo = 'Upload',' Envio ',' Recebimento ')+' de Arquivo '+Carquivo,0,0);

  Try
    Try
      if Tipo = 'Upload' then begin
         IdFTP1.Put (cArquivo, FtpCaminhoUpload+Carquivo, true);
      end else if Tipo = 

Open in new window

0
In my Delphi application, I determine the current directory by SysUtils.GetCurrentDir function. Of course, when the app is run, the current directory is the folder in which the installer put MyApp.exe file. By default, it is C:\Program Files\MyApp

Everything looks different now, after I packed my program in appx, in order to make a UWP application and submit it to Microsoft Store. Now the app goes to the folder C:\Program Files\WindowsApps\MyApp_1.0.0.0_x86__sp51hrchc9zqj.  However, the function GetCurrentDir returns a different address which is C:\WINDOWS\system32

What can I do about it? I need the address of the folder where the exe file is!
0
I´m running a miniature callcenter with business clients who use Microsoft Office 365 as their enterprise calendar system. The clients usually have anything from 10 to 200 employees using O365 calendars. I need to be able to get our callcenter program to tap into the client´s calendars and retreive information (free/busy is most important).

Some background info that may be useful: We run FreePBX (Asterisk) as our telephony platform. Our agents use an in-house developed program to handle the calls and get info about the clients. The program is fully customizable (developed in Delphi) and talks with a MySQL db where all the client info is stored.

When our callcenter agent gets a call to one of the client´s phone number, the client´s company info is displayed together with a complete listing of all the employees. We currently have no way of telling if the employee is free or busy, as we cannot access their calendar. I would need to get that information added to the employee info in our MySQL db. Perhaps synchronized once every 5 minutes.

How would you suggest me to go about this? I accept suggestions to 3rd party plugins (for example for Delphi). Freelance gig may also be accepted.

Thanks and sorry about my bad english.
0
I have several documents that are actually *.rtf files, but the extension was changed to *.doc.
Now I need to know if it is actually a *.rtf or a real *.doc file.

So I'm looking for a Delphi function that will determine if a document-file internally is ​a *.rtf of *.doc file.
The function should handle older version of word documents too (like Word 98).
0
Cloud Class® Course: C++ 11 Fundamentals
LVL 12
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

Hi can you tell me how to add Combo box in to Adv String grid
Ex
i need to add Col 1 Combobox 1, Col2 need to add Combobox 2
0
Hi

following scenario:
- Delphi 10.1 Berlin
- SQL Server Database with a table "myTable", two columns "colA" and "colB"
- Open the table with SELECT colA, colB, colA * colB AS multiplyResult FROM myTable
- Form with a tDbGrid, showing all the columns

Know my question: I want to modify colA or colB (in the tDnGrid) and want that the result is displayed immediately. Is there a possibility to refresh only that calculated value without calling the refresh-method of the query (after the refresh I have to locate the row again and if it is a large table it is a performance-problem)?

Thanks for your hints, Peter
0
I am looking for an easy way to verify that the PC where my program is running is connected to the Internet.
The program is mine and coded in Delphi XE
Thanks
0
When I try the program below I get
error  "OLE error 800A03EC"
When I put the formula
=SOMMEN.ALS(R[-8]K:R[-2]K;R[-8]K[-1]:R[-2]K[-1];">100";R[-8]K[-1]:R[-2]K[-1];"<200")
manualy in the Excel sheet on cell (11,2) everyting is ok.
In the attachment the test.xlsx file.

===================

unit Unit1;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, ComObj, StdCtrls;

type
  TForm1 = class(TForm)
    Button1: TButton;
    procedure Button1Click(Sender: TObject);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.Button1Click(Sender: TObject);
var ExcelApp : variant;
begin
  ExcelApp:= CreateOleObject('Excel.Application');
  ExcelApp.DisplayAlerts := False;
  ExcelApp.Workbooks.Open('c:\users\myself\temp\test.xlsx');
  //"=SOMMEN.ALS" is Dutch version of "=SUMIFS"
  ExcelApp.ActiveWorkbook.WorkSheets[1].Cells(11,2):='=SOMMEN.ALS(R[-8]K:R[-2]K;R[-8]K[-1]:R[-2]K[-1];">100";R[-8]K[-1]:R[-2]K[-1];"<200")';
  ExcelApp.Visible:=True;
end;

end.
test.xlsx
0
Can I use Delphi 10.2.2  FireDac TFDLocalSql   with Firebird ?
0
I had this question after viewing Image On A TButton.

I have the same problem, but, I don't know why, few days ago it worked until I did something wrong in Project Option or somewhere, I presume,and then no chanche to see a TButton with an image inside in my app (only button). In a new app it works (Win10 Rad Delphi 10,2) May be the problem is in the attached file, but......
0

Delphi

59K

Solutions

17K

Contributors

Delphi is the most powerful Object Pascal IDE and component library for cross-platform Native App Development with flexible Cloud services and broad IoT connectivity. It provides powerful VCL controls for Windows 10 and enables FMX development for Windows, Mac and Mobile. Delphi is your choice for ultrafast Enterprise Strong Development™. Look for increased memory for large projects, extended multi-monitor support, improved Object Inspector and much more. Delphi is 5x faster for development and deployment across multiple desktop, mobile, cloud and database platforms including 32-bit and 64-bit Windows 10.

Top Experts In
Delphi
<
Monthly
>