No file type appended when base filename contains a period
Hi,
We've noticed a problem lately when printing to file and the base filename
contains a period '.' other than at the end e.g. 'Tel. No. List'
This problem affects RB built in file types and also those of ExtraDevices
which we use.
Since we use a slightly customized print dialog, I've made the change shown
below.
I thought you might want to incorporate a fix to the standard dialog.
My modified code doesn't cater for the user adding a file extension manually
that differs from the default extension for the file type chosen but this
isn't an issue for us. It will always get the default extension appended to
it should they do so.
Regards, Paul.
PrintDialog.ValidateFileName;
lFileDevice :=
TppFileDeviceClass(cbxPrintToFileTypes.Items.Objects[cbxPrintToFileTypes.ItemIndex]);
if (lFileDevice = nil) then Exit;
lsFileName := edtPrintToFileName.Text;
//modified code
//--------------------------------------------------
LastDotPos := LastDelimiter('.', lsFileName);
if ( LastDotPos > 0 ) and ( LastDotPos <> Length(lsFileName) ) then
begin
lsExt := UpperCase(ExtractFileExt(lsFileName));
lsDefExt := '.' + UpperCase(lFileDevice.DefaultExt);
if ( lsExt <> lsDefExt ) then
lsFileName := lsFileName + lsDefExt;
end
else begin
//this block was the original code
{validate filename extension, append default ext if necessary }
lsExt := ExtractFileExt(lsFileName);
if lsExt = '' then
lsFileName := lsFileName + '.' + lFileDevice.DefaultExt
else if lsExt = '.' then
lsFileName := lsFileName + lFileDevice.DefaultExt;
end;
//--------------------------------------------------
FPrintToFilePath := SysUtils.ExtractFilePath(lsFileName);
...
We've noticed a problem lately when printing to file and the base filename
contains a period '.' other than at the end e.g. 'Tel. No. List'
This problem affects RB built in file types and also those of ExtraDevices
which we use.
Since we use a slightly customized print dialog, I've made the change shown
below.
I thought you might want to incorporate a fix to the standard dialog.
My modified code doesn't cater for the user adding a file extension manually
that differs from the default extension for the file type chosen but this
isn't an issue for us. It will always get the default extension appended to
it should they do so.
Regards, Paul.
PrintDialog.ValidateFileName;
lFileDevice :=
TppFileDeviceClass(cbxPrintToFileTypes.Items.Objects[cbxPrintToFileTypes.ItemIndex]);
if (lFileDevice = nil) then Exit;
lsFileName := edtPrintToFileName.Text;
//modified code
//--------------------------------------------------
LastDotPos := LastDelimiter('.', lsFileName);
if ( LastDotPos > 0 ) and ( LastDotPos <> Length(lsFileName) ) then
begin
lsExt := UpperCase(ExtractFileExt(lsFileName));
lsDefExt := '.' + UpperCase(lFileDevice.DefaultExt);
if ( lsExt <> lsDefExt ) then
lsFileName := lsFileName + lsDefExt;
end
else begin
//this block was the original code
{validate filename extension, append default ext if necessary }
lsExt := ExtractFileExt(lsFileName);
if lsExt = '' then
lsFileName := lsFileName + '.' + lFileDevice.DefaultExt
else if lsExt = '.' then
lsFileName := lsFileName + lFileDevice.DefaultExt;
end;
//--------------------------------------------------
FPrintToFilePath := SysUtils.ExtractFilePath(lsFileName);
...
This discussion has been closed.