Lazarus - loading picture form file - image

I have an issue with loading a picture from z file. The picture has a .png extension.
Can anyone explain me why it doesn't work anymore ?
if (FileExists('file.png')) then
Image1.Picture.LoadFromFile('file.png');
Errors:
Project project1 raised exception class 'PNGImageException' with message: This is not PNG-data
Project project1 raised exception class 'FPImageException' with message: Wrong image format

At the first create your image component:
MyPicture := TImage.Create(FormCanvas);
MyPicture.Name := 'picture';
MyPicture.Parent := FormCanvas;
V1 - use direct path
Edit_pic_path.Text := 'C:\Images\';
Prop_Picture_Name.Text := 'image.png';
try
if (FileExists(Edit_pic_path.Text + Prop_Picture_Name.Text)) then
begin
MyPicture.Picture.LoadFromFile(Edit_pic_path.Text + Prop_Picture_Name.Text);
end;
finally
end;
V2 - image must be in project folder
...
MyPicture.Picture.LoadFromFile(Prop_Picture_Name.Text);
...

Related

How to serve file referenced from HTML file using WebBroker (TIdHTTPWebBrokerBridge) and TWebModule

I built tiny http server (Delphi 10.2) to return some calculations to client on-line.
I used page producer with TPageProducer.HTMLFile set to local file.
The test.html file has reference to css file on local disk like: <link rel="stylesheet" href="data/style.css"> in the head section. It works from Firefox styling my html.
To be able to serve this css file from local folder I handled WebModule.BeforeDispatch:
procedure TWebModule1.WebModuleBeforeDispatch(Sender: TObject; Request: TWebRequest;
Response: TWebResponse; var Handled: Boolean);
var
LocalPath: String;
begin
if Request.PathInfo.StartsWith('/data/') then
begin
LocalPath := DataPath + StringReplace(Request.PathInfo, '/', '\', [rfReplaceAll]);
if FileExists(LocalPath) then
begin
Response.ContentStream := TFileStream.Create(LocalPath, fmShareDenyWrite);
Assert(Response.ContentStream.Size > 0);
end;
Handled := True;
end;
end;
When I run my server and go to address: http://localhost/data/style.css
I obtain proper contents of style.css file in a browser window as a result.
Why is it not used as style for my HTML file even if it is correctly read in OnBeforeDispatch when using address like http://localhost/test.html?
It seems that one file (CSS) is referenced from other (HTML) and this makes things cluttered.

Getting error when trying to install R Package "Tidytext"

Error: package or namespace load failed for ‘tidytext’ in library.dynam(lib, package, package.lib): shared object ‘stringi.so’ not found
6.
stop(msg, call. = FALSE, domain = NA)
5.
value[3L]
4.
tryCatchOne(expr, names, parentenv, handlers[[1L]])
3.
tryCatchList(expr, classes, parentenv, handlers)
2.
tryCatch({ attr(package, "LibPath") <- which.lib.loc ns <- loadNamespace(package, lib.loc) env <- attachNamespace(ns, pos = pos, deps) ...
1.
library(tidytext)
upon running
tidyverse:::tidyverse_attach()
tidyverse:::tidyverse_conflicts()
> tidyverse:::tidyverse_attach()
Error in library.dynam(lib, package, package.lib) :
shared object ‘stringi.so’ not found
> tidyverse:::tidyverse_conflicts()
Error in library.dynam(lib, package, package.lib) :
shared object ‘stringi.so’ not found
Try running install.packages('stringi')
See this issue thread for more details: https://github.com/bvieth/powsimR/issues/20
I personally found that when my OS updates R, all of my downloaded packages get broken in some weird way. I've yet to find a fix for it.

Pascal unhandles exception occured

When I run this procedure
procedure displaydir;
var count:integer;
directoryfile: file of tdir;
directory:array [1..100] of tdir;
begin
assignfile(directoryfile, 'directory.bin');
reset(directoryfile);
count:=0;
repeat
read(directoryfile,directory[count]);
writeln('Name: ',directory[count].name);
writeln('Telephone number: ',directory[count].tel);
writeln('Job title: ',directory[count].jobtitle);
writeln;
writeln;
count:=count+1;
until (directory[count-1].name = 'q');
end;
I get the error
An unhandled exception occurred at $00000000:
EAccessViolation: Access violation
$00000000
$2A005640
$B6F83F97
Unfortunately I couldn't find a solution on the internet, help is much appreciated!
You've declared an array directory as 1..100, but set count to 0 on first run through. directory[ 0] is out of range. You're probably trying to write to read only memory.

How to solve distinct-values error

How to solve this error in XQuery. I want the data to be distinct with out duplication in XML result. I tried to add distinct-values in front of the doc in for statement, but this error was depicted.
Engine name: Saxon-PE XQuery 9.5.1.3
Severity: fatal
Description: XPTY0019: Required item type of first operand of '/' is node(); supplied value has item type xs:anyAtomicType
Start location: 23:0
URL: http://www.w3.org/TR/xpath20/#ERRXPTY0019
This is code :
for $sv1 in distinct-values(doc('tc.xml')//term/year)
let $sv2 := doc('tc.xml')//term[year= $sv1]
let $sv3 := doc('tc.xml')//student[idStudent= $sv1/idStudent](:HERE IS THE ERROR LINE:)
let $sv4 := doc('tc.xml')//program[idStudent= $sv3/idStudent]
return
<Statistics>
{$sv1 }
<Count_Student>{count($sv2)}</Count_Student>
<a50_60>{count(doc('tc.xml')/mydb//program[doc('tc.xml')/mydb//term/year =$sv1][avg>= 50 and avg < 60])}</a50_60>
</Statistics>
thank you in advance.
distinct-values() will atomize your input, this means that $sv1/idStudent won't work because $sv1 is not an element. Instead of using $sv1 on the line that give an error I think you should be using $sv2.

How to let user to browse to a file to be copied with Inno Setup

I need user to browse to a file, select it, and then have this file copied from selected source to app folder.
Following this post
How to show/use the user selected app path {app} in InputDirPage in Inno Setup?
and Inno Setup documentation, i came to this piece of code:
[Files]
Source: {code:GetDBPath}; DestDir: "{app}"; Flags: confirmoverwrite uninsneveruninstall;
[Code]
var
SelectDBPage: TInputDirWizardPage;
DBPath: String;
procedure InitializeWizard;
begin
SelectDBPage := CreateInputDirPage(wpSelectDir, 'Select file', 'Select file', 'Select file', False, '');
SelectDBPage.Add('');
SelectDBPage.Values[0] := ExpandConstant('{src}\DB.FDB');
DBPath := SelectDBPage.Values[0];
end;
function GetDBPath():String;
begin
Result := DBPath;
end;
My problem is to retrieve file path. At instruction 'Source: {code:GetDBPath}' i get an 'Unknown filename prefix {code:' error.
How can I refer to the selected file path in [File] section?
Thank you
You need to add the external flag to the [Files] entry. This means the source will be evaluated at run time and CAN include {code:...} constants.
You're also not getting the correct value in your GetDBPath() function. You're returning the value of DBPath that isn't updated after creating the page, instead of getting the latest value form the SelectDBPage.Values[0].

Resources