Groups | Search | Server Info | Login | Register
Groups > comp.lang.pascal.delphi.misc > #732
| From | "P E Schoen" <paul@pstech-inc.com> |
|---|---|
| Newsgroups | comp.lang.pascal.delphi.misc |
| Subject | Strings and PChar (D4 Pro) |
| Date | 2016-08-27 05:39 -0400 |
| Organization | A noiseless patient Spider |
| Message-ID | <nprn44$mvb$1@dont-email.me> (permalink) |
This is probably a very basic question, but I may have been improperly
casting a string to PChar in some cases. For instance, I got the following
code to work as shown:
====================================================
procedure TfmOrtDatabase.btBackupClick(Sender: TObject);
var udfn: OrtData.TUserDataFile;
S, dbFileName, saveFileName, dirName: String;
// currDir: String;
currDir: array[0..50] of Char;
begin
if Application.MessageBox( 'Backup Database Files?',
'Backup', MB_YESNO ) = ID_YES then begin //1
// currDir := '01234567890123456789012345678901234567890123456789';
// SetLength(currDir,50);
GetCurrentDirectory(sizeof(currDir)+1, @currDir);
dirName := GetSystemFolder(CSIDL_PERSONAL);
dirName := dirName + '\Ortmaster';
SelectDirectory(dirName, [sdAllowCreate,sdPerformCreate], 0);
// SelectDirectory('Select Directory', dirName, dirName);
S := FormatDateTime('yyyymmdd', Now);
fmDBSaveDialog.InitialDir := dirName;
for udfn := udfCust to udfTypes do begin //2
dbFileName := ProgramDataFolder + '\' +
OrtData.UserFileName[udfn]+'.dbf';
fmDBSaveDialog.FileName := OrtData.UserFileName[udfn]+'.dbf';
if not (fmDBSaveDialog.Execute) then exit;
if (FileExists(dbFileName)) then begin //3
saveFileName := fmDBSaveDialog.FileName + '-' + S;
if not( CopyFile( pChar(dbFileName), PChar(saveFileName), FALSE ) )
then
MessageDlg('File Copy Error', mtInformation, [mbOK], 0);;
end; //-3
end; //-2
fmDBSaveDialog.InitialDir := dirName;
dbFileName := 'Ortmaster' + '.rcf';
fmDBSaveDialog.FileName := dbFileName;
dbFileName := ProgramDataFolder + '\Ortmaster' + '.rcf';
if not (fmDBSaveDialog.Execute) then exit;
if (FileExists(dbFileName)) then begin //2
saveFileName := fmDBSaveDialog.FileName + '-' + S;
if not( CopyFile( pChar(dbFileName), pChar(saveFileName), FALSE ) )
then
MessageDlg('File Copy Error', mtInformation, [mbOK], 0);;
end; //-2
SetCurrentDirectory(currDir);
end; //-1
end;
=========================================================
If I used an uninitialized string, the GetCurrentDirectory() function
failed, even when I initialized the string to a constant as shown. It's
rather late, and maybe my brain is fogged, but it seems like there should be
a better way to do this. It would be nice if there were a function like
GetSystemFolder() that returns a string.
BTW, the SelectDirectory() function seems to be what I was searching for in
a post from 7/20/15.
Also, I'm not sure why the current directory got changed by the function.
Thanks,
Paul
Back to comp.lang.pascal.delphi.misc | Previous | Next — Next in thread | Find similar
Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 05:39 -0400
Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:03 -0400
Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:28 -0400
Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 18:00 +0700
Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 13:41 +0200
Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 17:05 +0700
Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 06:15 -0400
Re: Strings and PChar (D4 Pro) JJ <jj4public@vfemail.net> - 2016-08-27 18:09 +0700
Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 13:12 +0200
Re: Strings and PChar (D4 Pro) "P E Schoen" <paul@pstech-inc.com> - 2016-08-27 18:59 -0400
Re: Strings and PChar (D4 Pro) Hans-Peter Diettrich <DrDiettrich1@aol.com> - 2016-08-27 12:50 +0200
csiph-web