Jump to content

TUniImage Invalid File Extension '.nnn' - PLEASE HELP!


eelias

Recommended Posts

Hi there.

 

I am doing some components on delphi Xe2 descendant from UniGui ones.

 

I have created a compound one that is inherited from TUniPanel and it has one TUniImage and TUniLabel that is created and have the TUniPanel as owner and parent.

 

I am trying with it to create a windows 8 button (that round images with a label below)

 

My component have 2 Picture properties, of type TPicture, one for the white image of the button and other for the black one.

 

I have an attribute that permit switch between the 2 images, that I use the following code:

  if HCColor = clWhite then
    FImage.Picture.Assign(PictureWhite);

  if HCColor = clBlack then
    FImage.Picture.Assign(PictureBlack);

Where the FImage is the TUniImage that was created when this component gets created.

 

There are 2 problems:

 

1 - On design time I can change the property from white to black and vice versa and it does change the image correctly as expected. However the first time the image never shows up. I have made all kind of change and debug and simply the first time never works. 

 

2 - When using on webmode the Image does appear corretly at first time, but if I try to change it it give me the message:

 

EInvalidGraphic "Unknown picture file extension (.nnn)"

 

I am assigning correctly, and the image is there. It is the same that worked on design mode. I see that the Picture is created as a file on the cache, but for some reason it is not getting loaded.

 

I am using PNG image and the server application is set to use PNG image.

 

I have made many components derived from the UniGUI ones, and all working correctly. THe only problem is this change of image.

 

This is the complete component, there are some specific stuff that my classes, but it is the same that is working from other components the only difference on this one is that I am assigning an Image that INSIDE the component, the images are already there:

unit NaharWebFlatButton;

interface

uses
  Nahar.Theme,
  NaharWebFrame,
  NaharWebThemeController, Vcl.ExtCtrls, Vcl.StdCtrls,
  System.SysUtils, System.Classes, Vcl.Controls, uniGUIBaseClasses, PngFunctions,
  uniGUIClasses, uniImage, UniPanel, Vcl.Graphics, UniGuiTypes, uniLabel;

type
  TNaharWebFlatButton = class(TUniPanel)
  private
    FThemeColor : TNaharPalleteColor;
    FCaption: string;
    FPictureBlack: TPicture;
    FPictureWhite: TPicture;
    FShowCaption: boolean;
    FOnClick: TNotifyEvent;
    procedure   OnObserver(Sender: TObject; AParam, AValue: Variant);
    procedure   UpdateColor;
    procedure   SetThemeColor(const Value: TNaharPalleteColor);
    function    GetThemeManager: TNaharThemeManager;
    procedure   SetCaption(const Value: string);
    procedure   SetShowCaption(const Value: boolean);
    procedure   OnPictureClick(Sender: TObject);
    procedure   SetOnClick(const Value: TNotifyEvent);
    procedure   SetPictureBlack(const Value: TPicture);
    procedure   SetPictureWhite(const Value: TPicture);
  protected
    FThemeController: TNaharThemeController;
    FImage: TUniImage;
    FLabel: TUnilabel;
  public
    constructor Create(AOwner: TComponent); override;
    destructor  Destroy; override;
    property    ThemeManager: TNaharThemeManager read GetThemeManager;
  published
    property    ThemeColor: TNaharPalleteColor read FThemeColor write SetThemeColor default npcMainColor;
    property    PictureWhite: TPicture read FPictureWhite write SetPictureWhite;
    property    PictureBlack: TPicture read FPictureBlack write SetPictureBlack;
    property    Caption: string read FCaption write SetCaption;
    property    ShowCaption: boolean read FShowCaption write SetShowCaption;
    property    Width default 25;
    property    Height default 25;
    property    OnClick: TNotifyEvent read FOnClick write SetOnClick;
  end;

procedure Register;

implementation

procedure Register;
begin
  RegisterComponents('NaharWeb Standard', [TNaharWebFlatButton]);
end;

{ TNaharWebFlatButton }

constructor TNaharWebFlatButton.Create(AOwner: TComponent);
begin
  inherited;

  FPictureBlack         := TPicture.Create;
  FPictureWhite         := TPicture.Create;
  Width                 := 25;
  Height                := 25;
  BorderStyle           := ubsNone;

  FImage                := TUniImage.Create(self);
  FImage.Parent         := self;
  FImage.Align          := alClient;
  FImage.Center         := true;
  FImage.Proportional   := true;
  FImage.Transparent    := true;
  FImage.Stretch        := true;
  FImage.OnClick        := OnPictureClick;

  FLabel                := TUniLabel.Create(Self);
  FLabel.Parent         := Self;
  FLabel.Align          := alBottom;
  FLabel.Alignment      := taCenter;
  FLabel.Visible        := false;
  FLabel.Text           := '';
  Caption               := '';

  FThemeColor := npcMainColor;

  FThemeController := LocateThemeController(AOwner);

  ThemeManager.AddObserver(OnObserver);

  UpdateColor;
end;

destructor TNaharWebFlatButton.Destroy;
begin
  ThemeManager.RemoveObserver(OnObserver);

  FPictureBlack.Free;
  FPictureWhite.Free;
  FImage.Free;
  FLabel.Free;

  inherited;
end;

function TNaharWebFlatButton.GetThemeManager: TNaharThemeManager;
begin
  if Assigned(FThemeController) then
    result := FThemeController.ThemeManager
  else
    result := NaharThemeManager;
end;

procedure TNaharWebFlatButton.OnObserver(Sender: TObject; AParam, AValue: Variant);
begin
  if AParam = 'currentpalletechanged' then
    UpdateColor;

end;

procedure TNaharWebFlatButton.OnPictureClick(Sender: TObject);
begin
  if Assigned(FOnClick) then
    FOnClick(Self);
end;

procedure TNaharWebFlatButton.SetCaption(const Value: string);
begin
  FCaption := Value;

  UpdateColor;
end;

procedure TNaharWebFlatButton.SetOnClick(const Value: TNotifyEvent);
begin
  FOnClick := Value;
end;

procedure TNaharWebFlatButton.SetPictureBlack(const Value: TPicture);
begin
  if Assigned(Value) then
    FPictureBlack.Assign(Value);

  UpdateColor;
end;

procedure TNaharWebFlatButton.SetPictureWhite(const Value: TPicture);
begin
  if Assigned(Value) then
    FPictureWhite.Assign(Value);

  UpdateColor;
end;

procedure TNaharWebFlatButton.SetShowCaption(const Value: boolean);
begin
  FShowCaption := Value;

  UpdateColor;
end;

procedure TNaharWebFlatButton.SetThemeColor(const Value: TNaharPalleteColor);
begin
  FThemeColor := Value;

  UpdateColor;
end;

procedure TNaharWebFlatButton.UpdateColor;
var
  HCColor : TColor;

begin
  if ShowCaption then
  begin
    FLabel.Visible    := true;
    FLabel.Align      := alBottom;
    FLabel.Text       := FCaption;
    FLabel.Alignment  := taCenter;
    FLabel.Font.Size  := Self.Font.Size;
    FLabel.Font.Name  := Self.Font.Name;
    FLabel.Font.Style := Self.Font.Style;
    FLabel.Font.Color := Self.Font.Color;
  end
  else
  begin
    FLabel.Visible    := false;
    FLabel.Text       := '';
    FLabel.Align      := alNone;
    FImage.Align      := alClient;
  end;

  if (FThemeColor = npcNone) or (FThemeColor = npcUnknown) then
    HCColor := ThemeManager.CurrentPallete.HighContrastColor(Color)
  else
    HCColor := ThemeManager.CurrentPallete.HighContrast(FThemeColor);

  if HCColor = clWhite then
    FImage.Picture.Assign(PictureWhite);

  if HCColor = clBlack then
    FImage.Picture.Assign(PictureBlack);

  if (FThemeColor = npcNone) or (FThemeColor = npcUnknown) then
    exit;

  Color      := ThemeManager.CurrentPallete.Color[FThemeColor];

  Font.Color := ThemeManager.CurrentPallete.HighContrast(FThemeColor);

  Font.Name  := ThemeManager.CurrentPallete.BodyFont;

  if ShowCaption then
  begin
    FLabel.Font.Name  := Self.Font.Name;
    FLabel.Font.Color := Self.Font.Color;
  end;
end;

end.

Any Clue?

 

Thank you

  • Upvote 1
Link to comment
Share on other sites

It seems that when setting the image on TPicture UniGUI saves it as a file and pass that to the Image on the ExtJS framework.

 

However for some reason, it is creating that cached image file, with extension .nnn but is having a bad time on attibuting it.

 

Farshad, you are the only one that I believe could give me an idea why setting the TPicture it is not getting changed and I get this error.

 

I have used the same PNG files for other things, I have TUniImage all over the place when I can set at runtime the image just fine.

 

This is the only place with problem, is there any context problem? I am trying to define a PNG image, is it going to use the settings of servermodule for that? I have no other idea on correct this problem.

 

Please!

  • Upvote 1
Link to comment
Share on other sites

  • 2 years later...
  • 9 months later...

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...