Rectangle 27 3

AppPath := TPath.GetHomePath; 
FileName := TPath.Combine(AppPath, 'File.txt');

is working fine. do not forget to add the unit System.IOUtils to your uses clause.

DELPHI XE5 Android - SAVE / LOAD file from SDCard - Stack Overflow

android delphi delphi-xe5
Rectangle 27 8

When you copy a file onto the clipboard from the hard drive, it simply copies the file's full path and filename in CF_HDROP format. You can use the DragQueryFile() function to read the filenames, eg:

uses
  Classes, Clipbrd, ShellAPI;

var
  hDrop: THandle
  MyStream: TMemoryStream;
  Files: TStringList;
  NumFiles, FileIdx: DWORD;
  FileName: array[0..MAX_PATH] of Char;
  I: Integer;
begin
  Files := TStringList.Create;
  try
    Clipboard.Open;
    try
      if Clipboard.HasFormat(CF_HDROP) then
      begin
        // DO NOT free this handle, the clipboard owns it!
        hDrop := Clipboard.GetAsHandle(CF_HDROP);
        NumFiles := DragQueryFile(hDrop, $FFFFFFFF, nil, 0);
        if NumFiles <> 0 then
        begin
          for FileIdx := 0 to NumFiles-1 do
          begin
            if DragQueryFile(hDrop, FileIdx, FileName, MAX_PATH) <> 0 then
              Files.Add(FileName);
          end;
        end;
      end;
    finally
      Clipboard.Close;
    end;
    for I := 0 to Files.Count-1 do
    begin
      MyStream := TMemoryStream.Create;
      try
        MyStream.LoadFromFile(Files[I]);
        MyStream.Position := 0;
        // use MyStream as needed...
      finally
        MyStream.Free;
      end;
    end;
  finally
    Files.Free;
  end;
end;

Thanks for clarification and fully working example! Also ShellAPI unit is required (DragQueryFile) in the uses clause.

delphi - How to load a stream with a file copied in Windows clipboard ...

delphi clipboard tstream
Rectangle 27 7

In VCL, TWebBrowser is a wrapper for Internet Explorer, specifically the IWebBrowser2 interface.

DLCTL_PRAGMA_NO_CACHE
Navigate2()

TWebBrowser wraps the IWebBrowser2 interface from Microsoft's Shell Doc Object and Control Library (SHDOCVW.DLL) to allow you to create a customized Web browsing application or to add Internet, file and network browsing, document viewing, and data downloading capabilities to your applications.

Flags [in] A pointer to a VARIANT of type VT_I4 or VT_I2 that specifies a combination of the values defined by the BrowserNavConstants enumeration.

typedef enum BrowserNavConstants {
    navOpenInNewWindow = 0x1,
    navNoHistory = 0x2,
    navNoReadFromCache = 0x4,
    navNoWriteToCache = 0x8,
    navAllowAutosearch = 0x10,
    navBrowserBar = 0x20,
    navHyperlink = 0x40,
    navEnforceRestricted = 0x80,
    navNewWindowsManaged = 0x0100,
    navUntrustedForDownload = 0x0200,
    navTrustedForActiveX = 0x0400,
    navOpenInNewTab = 0x0800,
    navOpenInBackgroundTab = 0x1000,
    navKeepWordWheelText = 0x2000,
    navVirtualTab = 0x4000,
    navBlockRedirectsXDomain = 0x8000,
    navOpenNewForegroundTab = 0x10000
} BrowserNavConstants;

As you can see, DLCTL_PRAGMA_NO_CACHE is not on that list. It is actually a flag you specify as an output value when implementing a handler for the browser's DISPID_AMBIENT_DLCONTROL property. Read the MSDN documentation:

The WebBrowser Control gives you control over what it downloads, displays, and executes. To gain this control, you need to implement your host's IDispatch so it handles DISPID_AMBIENT_DLCONTROL. When the WebBrowser Control is instantiated, it will call your IDispatch::Invoke with this ID. Set pvarResult to a combination of following flags, using the bitwise OR operator, to indicate your preferences. ... DLCTL_RESYNCHRONIZE and DLCTL_PRAGMA_NO_CACHE: These flags cause cache refreshes. With DLCTL_RESYNCHRONIZE, the server will be asked for update status. Cached files will be used if the server indicates that the cached information is up-to-date. With DLCTL_PRAGMA_NO_CACHE, files will be re-downloaded from the server regardless of the update status of the files. ...

So you would have to implement a custom IDispatch object and hook it into IWebBrowser2 in order to use DLCTL_PRAGMA_NO_CACHE correctly.

Alternatively, you might consider switching to TEmbeddedWB, which handles the browser customization for you, and has a DownloadOptions property that accepts DLCTL... flags, including DLCTL_PRAGMA_NO_CACHE.

delphi - How to always load a fresh page in TWebBrowser? - Stack Overf...

delphi twebbrowser
Rectangle 27 2

Since you are not getting an error when loading the JPEG image, I suspect the problem may be in the conversion from TJPEGImage to TBitmap. Unless you are going to be manipulating the image pixels, you don't need the conversion at all, you can assign the original TJPEGImage directly to the TImage. The VCL's TPicture class uses derived TGraphic classes so it can display images in their native formats, you should utilize that feature, eg:

procedure TForm1.btnBrowseClick(Sender: TObject);
var
  jpg: TJPEGImage;
  bmp: TBitmap;
begin
  OpenPicturedialog1.InitialDir := FindImageFolder(true);
  if OpenPictureDialog1.Execute then
  begin
    Image1.Picture.LoadFromFile(OpenPictureDialog1.FileName);

    if Image1.Picture.Graphic is TJPEGImage then
    begin
      if TJPEGImage(Image1.Picture.Graphic).Grayscale then
      begin
        Image2.Picture.Assign(Image1.Picture.Graphic);
      end else
      begin
        jpg := TJPEGImage.Create;
        try
          jpg.Assign(Image1.Picture.Graphic);
          jpg.Grayscale := True;
          Image2.Picture.Assign(jpg);
        finally
          jpg.Free;
        end;
      end;
    end else
    begin
      bmp := TBitmap.Create;
      try
        bmp.PixelFormat := pf32bit;
        bmp.Assign(Image1.Picture.Graphic);
        ...
        Image2.Picture.Assign(bmp);
      finally
        bmp.Free;
      end;
    end;
  end;
end;

Update: I did some tests in XE2 on Windows 7, and saw the same issue you do.

If I load the JPGs as-is using TImage.Picture.LoadFromFile(), they display fine only if the TImage.Stretch or TImage.Proportional property is True. If they are both set to False (the default), the images display blank.

If I load the JPGs into TJPEGImage first and then assign that to TBitmap, the conversion itself works fine (proved by saving the TBitmap to a .bmp file), and the bitmaps are displayed fine only if Stretch or Proportional are True, otherwise they display blank.

So, as another test, I tried using TPaintBox, drawing the images manually in its OnPaint event. If I use TCanvas.Draw() to draw the images as-is in their full dimensions, they display empty. If I use TCanvas.StretchDraw() to fit the images within the `PaintBox's client area, they display fine.

So, I think TCanvas is likely running into memory issues trying to display images at such larger dimensions. It has nothing to do with the particular type of JPGs being used (which are being loaded fine).

Update: nevermind what I said above. I see that the provided JPGs just have really large DPIs and happen to all be white in their top-left corners. If the TImage/TPaintBox is sized large to compensate, I can now see the images in their full dimensions (it is easier to see if the TImage is placed on a TScrollBox with TImage.AutoSize set to True). That would explain why stretch/proportional drawing works, by stretching the images to match TImage's dimensions when needed.

Hi Remy... I was doing that first and it was doing the same thing, only on some pictures. So I retested that to verify, still blank. Pushed out zipped folder of the three images to a download folder for testing. I moved this code line, [ Image1.Picture.LoadFromFile(name);], right to the top inside the try code and removed the [Image1.Picture.Assign(bmp)] to retest it.

I saw your comment from this post earlier [stackoverflow.com/questions/22291162/ and I wondered if there was a formatting change for sRGB vs. regular RGB files as there is in 24-bit vs. 32-bit files. If there is that and it isn't covered in the component or JPEG file, I could see where it would just display blank.

thx for the update, I tried the stretchDraw and scrollbox earlier, but I may have missed the Autosize option. I'll give that a go.

AutoSize is off by default. Only needed to check that option in the form image component and it worked as expected. Thx so much. Tomorrow, I'm going to rollin' the newer grayscale routine I was testing today, and our software rev will be complete. I can't believe I missed that checkbox. ps. .Assign(bmp) works as well as .Picture.LoadFromFile(name) with the checkbox set to [True]

Delphi TImage: How do I display images that are larger than the TImage...

image delphi bitmap jpeg srgb
Rectangle 27 3

Since I use www.ghisler.com (counter is at bottom) I can use

procedure TForm2.Button2Click(Sender: TObject);
var
  Flags: OLEVariant;

begin
  Flags:=4; //NavNoReadFromCache
  WebBrowser1.Navigate('http://www.ghisler.com/', Flags);
end;

and it works perfectly (Delphi XE7). I see TC main page, click on hyperlink then on Button2 again and counter is new. When I use Navigate(URL) only, counter is still the same.

We all LOVE Ghisler!!!!!!!! Don't we? Total Commander is definitively and without doubt my favorite program. Mr. Ghisler, one million thanks for that jewellery. Maybe Embarcadero can learn something from him (like software without bugs IS possible).

delphi - How to always load a fresh page in TWebBrowser? - Stack Overf...

delphi twebbrowser
Rectangle 27 3

Looking at your screenshot it seems the original file is in the Debug binaries folder of your application. Try to move the file in the project folder and retry (of course you have to re-add the new file location to your deploy options).

The binaries folder may be cleaned up at each build, deleting your original file just before trying to deploy it to the device.

No that did not work. I removed the old instance of the file from the deploy manager and did a rebuild. I moved the tags.txt file to my project directory and then re-added it to the deploy manager. Once again, when the file is added, the remote path says ".\". I tried it with that path and got my original results and error. I then changed the remote path to "assets\files", and still get the exact same results and error

Sorry, Andrea, that did work. If I added the file to the projects folder and change the remote path from the default ".\" to "assets\internal", it works!

Load text file into stringlist in Delphi XE-5 Firemonkey Android App -...

android delphi firemonkey delphi-xe5
Rectangle 27 2

PixelFormat
procedure TForm1.FormPaint(Sender: TObject);
var
  bm: TBitmap;
  y: Integer;
  sl: PRGBQuad;
  x: Integer;
begin

  bm := TBitmap.Create;
  try
    bm.SetSize(1024, 1024);
    bm.PixelFormat := pf32bit;
    for y := 0 to bm.Height - 1 do
    begin
      sl := bm.ScanLine[y];
      for x := 0 to bm.Width - 1 do
      begin
        sl.rgbBlue := 255 * x div bm.Width;
        sl.rgbRed := 255 * y div bm.Height;
        sl.rgbGreen := 255 * x div bm.Width;
        inc(sl);
      end;
    end;

    Canvas.Draw(0, 0, bm);
  finally
    bm.Free;
  end;

end;

delphi - How do I draw with scanlines without loading an image first? ...

delphi delphi-xe tbitmap
Rectangle 27 2

You can return your descendant of TCefContentFilterOwn in which you implement ProcessData method. There you can set SubstituteData to an instance of TCefStreamReaderRef which will be loaded by the browser instead of the received data.

delphi - Deplhi: Filtering loaded HTML by chromium enbedded (CEF VCL) ...

delphi interface filter chromium chromium-embedded
Rectangle 27 2

All bitmaps in FMX are 32-bit, and they are loaded and saved using code from the OS, which is all 32-bit.

So, the real answer is that all bitmaps have an alpha channel.

But, what you really want to know is whether the bitmap uses the alpha channel, and the only way to tell this would be to iterate over every pixel and see if any have an alpha channel which is <> 255.

I would recommmend something like the following (untested):

function TBitmap.IsAlpha(Bitmap: TBitmap): Boolean;
var
  I, j: Integer;
  Bits: PAlphaColorRecArray;
begin
  Bits := PAlphaColorRecArray(StartLine);
  for j := 0 to Height - 1 do
    for I := 0 to Width - 1 do
    begin
      if Bits[I + (j * Width)].A <> 255 then
      begin
        Result := True;
        EXIT;
      end;
    end;
  Result := False;
end;

You right, I don't like this solution although I had to use it, it is exactly what I want to avoid. Hence the question.

delphi - How to check if the PNG image loaded into FMX.TBitmap has an ...

delphi png delphi-xe2 firemonkey tbitmap
Rectangle 27 2

Following function checks if a PNG file has a transparency channel. This is easy, since the main PNG header has a fixed length and the data information block IHDR must be the first occurring block.

function PngHasAlphaLayer(f: String): Boolean;
var
  fs: TFileStream;
  colorType: Byte;
begin
  fs := TFileStream.Create(f, fmOpenRead);
  fs.Position := 25;
  fs.Read(colorType, 1);
  fs.Free;
  Result := colorType and (1 shl 2) <> 0;
end;

So it is stored in the 26th byte (or 0x19 as hex), in the 3rd bit.

However, this function does not check for a valid file structure for simplicity reasons. So it should be used after the PNG image has been loaded to TBitmap and then its boolean value for transparency support could be stored e. g. in the Tag property of TImage (or wherever you want).

delphi - How to check if the PNG image loaded into FMX.TBitmap has an ...

delphi png delphi-xe2 firemonkey tbitmap
Rectangle 27 0

For now the problem are solved by adding another twebbrowser to the project. (On a new tab). This webbrowser handle the login and keep the required php session alive. (It is automatic keept alive as long as the window stay open). Now Im able to load my own modifyed code without access denied.

Thanks for all your help.

delphi twebbrowser modify html before loaded - Stack Overflow

delphi twebbrowser
Rectangle 27 0

I just added a resource named SampleBitmap (a bitmap image) to a new VCL project. Then I added a TImage control, and gave it an OnClick handler:

procedure TForm1.Image1Click(Sender: TObject);
begin
  Image1.Picture.Bitmap.LoadFromResourceName(HInstance, 'SampleBitmap');
end;

The problem is most likely that you are using a JPG image, and not a Bitmap. You cannot load a JPG image into a TBitmap. So, what to do? Well, add JPEG to your uses clause, and do

procedure TForm5.Image1Click(Sender: TObject);
var
  RS: TResourceStream;
  JPGImage: TJPEGImage;
begin
  JPGImage := TJPEGImage.Create;
  try
    RS := TResourceStream.Create(hInstance, 'JpgImage', RT_RCDATA);
    try
      JPGImage.LoadFromStream(RS);
      Image1.Picture.Graphic := JPGImage;
    finally
      RS.Free;
    end;
  finally
    JPGImage.Free;
  end;
end;

Interesting, nothing happens onload, but onclick it does. However the onclick event (same as yours, I did change the resource name) returns an error saying it can't find the resource.

@Skeela87: Well, the above example is made to execute onclick, not onload. I just gave you the code to load the image. It is up to you to place the code at the right place in your code. Further, SampleBitmap and JpgImage are the names of the resources in my sample. In your case, the resource is called Splashscreen_Background instead.

Yeh, I've got that, I made my comment on your original post. But that works fine, TYVM. I did load a JPG, I hadn't realised that, I'm more of a VB person myself.

@Uwe: Oh, the bug in finally was a really cool one! Thanks for correcting it!

+1 for the JPG catch and code.

delphi - Load image from embedded resource - Stack Overflow

image delphi resources embedded-resource
Rectangle 27 0

AppPath := TPath.GetHomePath; 
FileName := TPath.Combine(AppPath, 'File.txt');

is working fine. do not forget to add the unit System.IOUtils to your uses clause.

DELPHI XE5 Android - SAVE / LOAD file from SDCard - Stack Overflow

android delphi delphi-xe5
Rectangle 27 0

procedure Tform1.addCat (kategorija : string);
var
  Doc: IXMLDocument;
  data: IXMLNode;
  xmlNode : IXMLNode;
  newCat : IXMLNode;
begin
  Doc := LoadXMLDocument('Project1.XML');
  data := Doc.DocumentElement;
  xmlNode := data.ChildNodes.FindNode('Kategorijos');
  newCat := xmlNode.AddChild('cat1');
  newCat.Text := kategorija;
  Doc.SaveToFile('Project1.XML');
end;

Delphi load XML - Stack Overflow

xml delphi pascal
Rectangle 27 0

I think you need a tool button OnClick handler that can be as simple as this:

procedure TMyForm.ToolButton1Click(Sender: TObject);
begin
  if Assigned(ActiveControl) then begin
    Application.HelpContext(ActiveControl.HelpContext);
  end;
end;

What makes this work is the fact that the controls on a toolbar do not ever become the active control.

Thanks this works in terms of bringing up the help system. However, the help button is on the toolbar of the main form. When I use this code, the help system is called with the help for the form which is being viewed, even though I have focus in a control that has its own context sensitive help? If I am on the grid and press F1 I get help for the grid

I tested the code when I wrote the answer. It works. There must be something unusual in your app.

Hi David its fine now this worked, I just had to write some code that goes back up the control's hierarchy. We use DevExpress grids, so the active control in my case was a cell in the grid, I needed to go back up to the parent, i.e. the grid

Simulate F1 kepress on active control to load help system - Delphi - S...

delphi delphi-2010
Rectangle 27 0

There's something wrong with your toolbar. The system toolbar doesn't ordinarily get the focus it's never the active control. If you're using a real TToolBar and TToolButton, you won't have this problem. Even TSpeedButton won't have this problem. Use the right control for the job.

Also, don't try to "simulate" a keyboard event. Just call Application.HelpContext directly.

Thanks for this Rob, however, as I just mentioned above I have a problem now where application.contextid appears to be 1 level too high? Instead of being the grid's context id it is the parent form's id?

There are question marks in your comments, but I don't know what question you're asking.

Hi Rob I was trying to figure out why the context number was wrong, but as explained above I have sorted it now thanks for your help

Simulate F1 kepress on active control to load help system - Delphi - S...

delphi delphi-2010
Rectangle 27 0

Since you have a fixed length that you're working with, you can build an access class based on TList with a TWriter and TReader that will take your records into account. You'll have none of the overhead of a TStringList (not that it's a bad thing, but if you don't need it, why have it) and you can build in your own access to records into the class. Ultimately it depends on what you are trying to accomplish with the data once you have it loaded into memory. While TStringlist is easy to use, it isn't as efficient as "rolling your own".

However, efficiency in data manipulation may not be that much of an issue, as you are using text files to hold a database. If you just need to read in and make decisions based on data in the file, the more flexible TList may be overkill.

I doubt the length of text on each line is fixed; The OP says It contains 150 field with each at least 50 characters. I think the fix quantity is the number of fields.

Is using TStringList to load huge text file the best way in Delphi? - ...

delphi text-files
Rectangle 27 0

It is possible to configure Delphi to debug itself. You launch a second copy of Delphi, and you might be able to see where in your code, and the only reasonable thing I can assume is that suddenly there is a problem with the code of the third party library components. To locate the source and line number of that crash, the Delphi debugger itself may be of some use.

Simply launch the third party component with Delphi.exe as the host executable (for Delphi 6 and 7), or bds.exe (for more recent Delphi versions). (In the IDE using Run Parameters, in the Host Application, put delphi.exe or bds.exe)

Then once you've located the source of the exception and fixed the code and recompiled the component packages containing that code, your problem may be solved.

(Note that the madExcept idea is equivalent in that it might also give you a stack traceback to help you find what code is crashing, but in case it doesn't this technique is also valuable to know about.)

crash - Loading a particular frame in Delphi 6 causes it to exit immed...

delphi crash vcl
Rectangle 27 0

You can try with a file with attributes FILE_ATTRIBUTE_TEMPORARY and FILE_FLAG_DELETE_ON_CLOSE. Such a file is (if enough cache memory is available) not written on harddisk and deleted when your application is closed.

And there ist an article here:

This is a very nice idea:) However, I think the file still can be copied during the time when application is opened? Anyway, well deserved +1 :)

Well, not so easy, because the file is only in the cache. Maybe it ist possible, but not without mayor difficulties. 100% security is not possible, every file and data in your computers memory can be copied...

delphi - Is there a way to load a Crystal Report 9.0 file from a strea...

delphi com crystal-reports activex
Rectangle 27 0

You could use TADOQuery to limit the result set with a sql query. Or you could use TADOTable and set the CursorLocation to a Server side cursor to prevent the client loading the complete resultset in memory.

How to prevent Delphi ADO from loading the entire table into memory? -...

delphi ado